]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listeners: make listeners count consistent with reality
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Sep 2017 06:18:11 +0000 (08:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 15 Sep 2017 09:49:52 +0000 (11:49 +0200)
Some places call delete_listener() then decrement the number of
listeners and jobs. At least one other place calls delete_listener()
without doing so, but since it's in deinit(), it's harmless and cannot
risk to cause zombie processes to survive. Given that the number of
listeners and jobs is incremented when creating the listeners, it's
much more logical to symmetrically decrement them when deleting such
listeners.

include/types/global.h
src/listener.c
src/proxy.c

index 0a6ece71fcc517b504ae2589cf7573b1f5cbeece..37fbaca5962067d25992fd3fa25cb862236b1ce0 100644 (file)
@@ -170,7 +170,7 @@ extern int  pid;                /* current process id */
 extern int  relative_pid;       /* process id starting at 1 */
 extern int  actconn;            /* # of active sessions */
 extern int  listeners;
-extern int  jobs;               /* # of active jobs */
+extern int  jobs;               /* # of active jobs (listeners, sessions, open devices) */
 extern struct chunk trash;
 extern int nb_oldpids;          /* contains the number of old pids found */
 extern const int zero;
index 47bed179ef46348030c897dc30deb64fd143c8da..d193b511a06f8cb709a5a567ce079d00c7b51e6b 100644 (file)
@@ -343,8 +343,9 @@ int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
 
 /* Delete a listener from its protocol's list of listeners. The listener's
  * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's
- * number of listeners is updated. Note that the listener must have previously
- * been unbound. This is the generic function to use to remove a listener.
+ * number of listeners is updated, as well as the global number of listeners
+ * and jobs. Note that the listener must have previously been unbound. This
+ * is the generic function to use to remove a listener.
  */
 void delete_listener(struct listener *listener)
 {
@@ -353,6 +354,8 @@ void delete_listener(struct listener *listener)
        listener->state = LI_INIT;
        LIST_DEL(&listener->proto_list);
        listener->proto->nb_listeners--;
+       listeners--;
+       jobs--;
 }
 
 /* This function is called on a read event from a listening socket, corresponding
index 0bbce62c8d001408ef851d58d683296054c49a84..ec1f60a9e09d03a8215ab784d260fe5eafb3afdf 100644 (file)
@@ -1080,8 +1080,6 @@ void zombify_proxy(struct proxy *p)
                unbind_listener_no_close(l);
                if (l->state >= LI_ASSIGNED) {
                        delete_listener(l);
-                       listeners--;
-                       jobs--;
                }
                /*
                 * Pretend we're still up and running so that the fd
@@ -1120,8 +1118,6 @@ void stop_proxy(struct proxy *p)
                unbind_listener(l);
                if (l->state >= LI_ASSIGNED) {
                        delete_listener(l);
-                       listeners--;
-                       jobs--;
                }
        }
        p->state = PR_STSTOPPED;