Skip to content

How to Fix HAProxy Stats Socket Connection Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix HAProxy Stats Socket Connection Error. We cover key concepts, practical examples, and best practices.

HAProxy stats socket returns Permission denied or No such file or directory when running socat or echo commands — the socket path is wrong or the user does not have access.

The Problem

$ echo "show info" | socat /var/run/haproxy.sock stdio
2026/06/24 10:00:00 socat[1234] E connect(5, AF=1,
"/var/run/haproxy.sock", 27): Permission denied

Step-by-Step Fix

Step 1: Verify the socket path

ls -la /var/run/haproxy.sock

Step 2: Configure the stats socket

# /etc/haproxy/haproxy.cfg
global
  stats socket /var/run/haproxy.sock mode 660 level admin
  stats socket ipv4@127.0.0.1:9999 level admin

Step 3: Modify socket permissions

sudo chmod 660 /var/run/haproxy.sock
sudo chown haproxy:haproxy /var/run/haproxy.sock

Step 4: Add user to haproxy group

sudo usermod -aG haproxy $USER
# Log out and back in for group change to take effect

Step 5: Test socket commands

echo "show info" | socat /var/run/haproxy.sock stdio
echo "show stat" | socat /var/run/haproxy.sock stdio

Expected output:

Name: HAProxy
Version: 2.8.0
Release_date: 2023/06/01
...

Step 6: Use TCP socket instead

global
  stats socket /var/run/haproxy.sock mode 660 level admin
  stats bind-process all

Prevention Tips

  • Set restrictive permissions (660) on the stats socket
  • Use IP-based stats socket for remote administration
  • Password-protect stats access in production
  • Monitor socket access in HAProxy logs

Common Mistakes with stats socket

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world HAPROXY code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the HAProxy stats socket used for?

The stats socket is a Unix domain socket that provides an admin interface to HAProxy. You can check server status, enable/disable servers, view statistics, and modify runtime settings without restarting HAProxy.

Why does "show info" return empty results on the socket?

The socket might be bound but the HAProxy process is not the one managing it. Check ps aux | grep haproxy to confirm the correct process. Also verify the socket level is set to admin for full command access.

How do I make the stats socket accessible to a Docker container?

Mount the socket directory as a volume: -v /var/run/haproxy:/var/run/haproxy. Inside the container, install socat and connect with echo "show info" | socat /var/run/haproxy.sock stdio.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro