From b5654f6ff425b5d2deadad84fe6f31fc10e9d5c6 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 7 Dec 2008 16:45:10 +0100 Subject: [PATCH] [MINOR] move the listener reference from fd to session The listener referenced in the fd was only used to check the listener state upon session termination. There was no guarantee that the FD had not been reassigned by the moment it was processed, so this was a bit racy. Having it in the session is more robust. --- include/types/fd.h | 3 +-- include/types/session.h | 1 + src/client.c | 2 +- src/proto_tcp.c | 1 - src/proto_uxst.c | 17 +++++++---------- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/include/types/fd.h b/include/types/fd.h index 97e14b14d..c413245e1 100644 --- a/include/types/fd.h +++ b/include/types/fd.h @@ -3,7 +3,7 @@ File descriptors states. Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 2.1 @@ -70,7 +70,6 @@ struct fdtab { unsigned char ev; /* event seen in return of poll() : FD_POLL_* */ struct sockaddr *peeraddr; /* pointer to peer's network address, or NULL if unset */ socklen_t peerlen; /* peer's address length, or 0 if unset */ - struct listener *listener; /* the listener which created this fd, or NULL if unset */ }; /* diff --git a/include/types/session.h b/include/types/session.h index 574f93341..eaa053fbf 100644 --- a/include/types/session.h +++ b/include/types/session.h @@ -155,6 +155,7 @@ struct session { struct list list; /* position in global sessions list */ struct task *task; /* the task associated with this session */ /* application specific below */ + struct listener *listener; /* the listener by which the request arrived */ struct proxy *fe; /* the proxy this session depends on for the client side */ struct proxy *be; /* the proxy this session depends on for the server side */ int conn_retries; /* number of connect retries left */ diff --git a/src/client.c b/src/client.c index a01bb527e..a9625dac1 100644 --- a/src/client.c +++ b/src/client.c @@ -157,6 +157,7 @@ int event_accept(int fd) { t->context = s; s->task = t; + s->listener = l; s->be = s->fe = p; /* in HTTP mode, content switching requires that the backend @@ -397,7 +398,6 @@ int event_accept(int fd) { fd_insert(cfd); fdtab[cfd].owner = &s->si[0]; - fdtab[cfd].listener = l; fdtab[cfd].state = FD_STREADY; fdtab[cfd].cb[DIR_RD].f = l->proto->read; fdtab[cfd].cb[DIR_RD].b = s->req; diff --git a/src/proto_tcp.c b/src/proto_tcp.c index ce0c43ac6..5a1424f3a 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -266,7 +266,6 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen) fdtab[fd].state = FD_STLISTEN; fdtab[fd].peeraddr = NULL; fdtab[fd].peerlen = 0; - fdtab[fd].listener = NULL; tcp_return: if (msg && errlen) strlcpy2(errmsg, msg, errlen); diff --git a/src/proto_uxst.c b/src/proto_uxst.c index b3bf7545c..d7567509e 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -270,7 +270,6 @@ static int uxst_bind_listener(struct listener *listener) fdtab[fd].state = FD_STLISTEN; fdtab[fd].peeraddr = NULL; fdtab[fd].peerlen = 0; - fdtab[fd].listener = NULL; return ERR_NONE; } @@ -438,6 +437,7 @@ int uxst_event_accept(int fd) { t->nice = -64; /* we want to boost priority for local stats */ s->task = t; + s->listener = l; s->fe = NULL; s->be = NULL; @@ -518,7 +518,6 @@ int uxst_event_accept(int fd) { fd_insert(cfd); fdtab[cfd].owner = &s->si[0]; - fdtab[cfd].listener = l; fdtab[cfd].state = FD_STREADY; fdtab[cfd].cb[DIR_RD].f = l->proto->read; fdtab[cfd].cb[DIR_RD].b = s->req; @@ -695,7 +694,6 @@ int uxst_req_analyser_stats(struct session *s, struct buffer *req) void uxst_process_session(struct task *t, int *next) { struct session *s = t->context; - struct listener *listener; int resync; unsigned int rqf_last, rpf_last; @@ -937,14 +935,13 @@ void uxst_process_session(struct task *t, int *next) } actconn--; - listener = fdtab[s->si[0].fd].listener; - if (listener) { - listener->nbconn--; - if (listener->state == LI_FULL && - listener->nbconn < listener->maxconn) { + if (s->listener) { + s->listener->nbconn--; + if (s->listener->state == LI_FULL && + s->listener->nbconn < s->listener->maxconn) { /* we should reactivate the listener */ - EV_FD_SET(listener->fd, DIR_RD); - listener->state = LI_READY; + EV_FD_SET(s->listener->fd, DIR_RD); + s->listener->state = LI_READY; } }