]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] session: account per-listener connections
authorWilly Tarreau <w@1wt.eu>
Sun, 16 Aug 2009 16:20:44 +0000 (18:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 16 Aug 2009 17:32:44 +0000 (19:32 +0200)
In order to merge the unix session handling code, we have to maintain
the number of per-listener connections in the session. This was only
performed for unix sockets till now.

src/client.c
src/session.c

index cb11727548bc0fa5f6e269e5bf2d650611855331..93bd8946a2338896d9370408d0b5d8d7fb1377cb 100644 (file)
@@ -108,6 +108,16 @@ int event_accept(int fd) {
                        }
                }
 
+               if (l->nbconn >= l->maxconn) {
+                       /* too many connections, we shoot this one and return.
+                        * FIXME: it would be better to simply switch the listener's
+                        * state to LI_FULL and disable the FD. We could re-enable
+                        * it upon fd_delete(), but this requires all protocols to
+                        * be switched.
+                        */
+                       goto out_close;
+               }
+
                if ((s = pool_alloc2(pool2_session)) == NULL) { /* disable this proxy for a while */
                        Alert("out of memory in event_accept().\n");
                        EV_FD_CLR(fd, DIR_RD);
@@ -458,6 +468,12 @@ int event_accept(int fd) {
                 */
                task_wakeup(t, TASK_WOKEN_INIT);
 
+               l->nbconn++; /* warning! right now, it's up to the handler to decrease this */
+               if (l->nbconn >= l->maxconn) {
+                       EV_FD_CLR(l->fd, DIR_RD);
+                       l->state = LI_FULL;
+               }
+
                p->feconn++;  /* beconn will be increased later */
                if (p->feconn > p->feconn_max)
                        p->feconn_max = p->feconn;
index 5213dcdc26cfac1fe3c666b2f937841baf9aa2e2..1a187900211dc74d9e5e7b4c2c7875e34ef07d20 100644 (file)
@@ -1206,6 +1206,13 @@ resync_stream_interface:
        if (s->flags & SN_BE_ASSIGNED)
                s->be->beconn--;
        actconn--;
+       s->listener->nbconn--;
+       if (s->listener->state == LI_FULL &&
+           s->listener->nbconn < s->listener->maxconn) {
+               /* we should reactivate the listener */
+               EV_FD_SET(s->listener->fd, DIR_RD);
+               s->listener->state = LI_READY;
+       }
 
        if (unlikely((global.mode & MODE_DEBUG) &&
                     (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {