]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: listener: stop unbound listeners on startup
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Apr 2016 10:05:02 +0000 (12:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 14 Apr 2016 10:05:02 +0000 (12:05 +0200)
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.

src/listener.c

index 566b34082ac85119d246771e86254330f4adcdf1..59385f04fb0dbd9a996bb1f438d95c5e81be1787 100644 (file)
@@ -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);