From: Willy Tarreau Date: Thu, 14 Apr 2016 10:05:02 +0000 (+0200) Subject: BUG/MINOR: listener: stop unbound listeners on startup X-Git-Tag: v1.7-dev3~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6c06d0f65b356bb586f38b41305ccf42d2aedde;p=thirdparty%2Fhaproxy.git BUG/MINOR: listener: stop unbound listeners on startup When a listener is not bound to a process its frontend belongs to, it is only paused and not stopped. This creates confusion from the outside as "netstat -ltnp" for example will report only the parent process as the listener instead of the effective one. "ss -lnp" will report that all processes are listening to all sockets. This is confusing enough to suggest a fix. Now we simply stop the unused listeners. Example with this simple config : global nbproc 4 frontend haproxy_test bind-process 1-40 bind :12345 process 1 bind :12345 process 2 bind :12345 process 3 bind :12345 process 4 Before the patch : $ netstat -ltnp Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 30457/./haproxy tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 30457/./haproxy tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 30457/./haproxy tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 30457/./haproxy After the patch : $ netstat -ltnp Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 30504/./haproxy tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 30503/./haproxy tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 30502/./haproxy tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 30501/./haproxy This patch may be backported to 1.6 and 1.5, but it relies on commit 7a798e5 ("CLEANUP: fix inconsistency between fd->iocb, proto->accept and accept()") since it will expose an API inconsistency by including listener.h in the .c. --- diff --git a/src/listener.c b/src/listener.c index 566b34082a..59385f04fb 100644 --- a/src/listener.c +++ b/src/listener.c @@ -57,8 +57,7 @@ void enable_listener(struct listener *listener) /* we don't want to enable this listener and don't * want any fd event to reach it. */ - fd_stop_recv(listener->fd); - listener->state = LI_PAUSED; + unbind_listener(listener); } else if (listener->nbconn < listener->maxconn) { fd_want_recv(listener->fd);