aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-07-06 10:54:27 +0000
committerOmar Polo <op@omarpolo.com>2021-07-06 10:54:27 +0000
commit090b8a89faa34cdc41c41e32845f1f5b444536e4 (patch)
treee8aa7a36f260448c4c00c0f26bcb18d731aabd54 /server.c
parentea976e8743ad3b3263faae00d88e40bcf727097d (diff)
gracefully shut down fastcgi backends
we need to delete the events associated with the backends, otherwise the server process won't ever quit. Here, we add a pending counter to every backend and shut down immediately if they aren't handling any client; otherwise we try to close them as soon as possible (i.e. when they close the connection to the last connected client.)
Diffstat (limited to 'server.c')
-rw-r--r--server.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/server.c b/server.c
index d07a642..93e5ffd 100644
--- a/server.c
+++ b/server.c
@@ -26,6 +26,8 @@
#include <limits.h>
#include <string.h>
+int shutting_down;
+
struct client clients[MAX_USERS];
static struct tls *ctx;
@@ -1246,12 +1248,16 @@ handle_imsg_fcgi_fd(struct imsgbuf *ibuf, struct imsg *imsg, size_t len)
static void
handle_imsg_quit(struct imsgbuf *ibuf, struct imsg *imsg, size_t len)
{
+ size_t i;
+
(void)imsg;
(void)len;
/* don't call event_loopbreak since we want to finish to
* handle the ongoing connections. */
+ shutting_down = 1;
+
event_del(&e4);
if (has_ipv6)
event_del(&e6);
@@ -1259,6 +1265,17 @@ handle_imsg_quit(struct imsgbuf *ibuf, struct imsg *imsg, size_t len)
signal_del(&siginfo);
event_del(&imsgev);
signal_del(&sigusr2);
+
+ for (i = 0; i < FCGI_MAX; ++i) {
+ if (fcgi[i].path == NULL && fcgi[i].prog == NULL)
+ break;
+
+ if (!event_pending(&fcgi[i].e, EV_READ, NULL) ||
+ fcgi[i].pending != 0)
+ continue;
+
+ fcgi_close_backend(&fcgi[i]);
+ }
}
static void