diff options
author | Omar Polo <op@omarpolo.com> | 2021-07-06 10:54:27 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-07-06 10:54:27 +0000 |
commit | 090b8a89faa34cdc41c41e32845f1f5b444536e4 (patch) | |
tree | e8aa7a36f260448c4c00c0f26bcb18d731aabd54 /fcgi.c | |
parent | ea976e8743ad3b3263faae00d88e40bcf727097d (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 'fcgi.c')
-rw-r--r-- | fcgi.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -381,9 +381,16 @@ close_all(struct fcgi *f) start_reply(c, CGI_ERROR, "CGI error"); } + fcgi_close_backend(f); +} + +void +fcgi_close_backend(struct fcgi *f) +{ event_del(&f->e); close(f->fd); f->fd = -1; + f->pending = 0; f->s = FCGI_OFF; } @@ -413,6 +420,8 @@ handle_fcgi(int sock, short event, void *d) if (must_read(sock, (char*)&end, sizeof(end)) == -1) goto err; /* TODO: do something with the status? */ + + f->pending--; c->fcgi = -1; c->next = close_conn; event_once(c->fd, EV_WRITE, ©_mbuf, c, NULL); @@ -447,6 +456,10 @@ handle_fcgi(int sock, short event, void *d) if (!consume(sock, h.padding)) goto err; + + if (f->pending == 0 && shutting_down) + fcgi_close_backend(f); + return; err: @@ -462,6 +475,8 @@ send_fcgi_req(struct fcgi *f, struct client *c) struct tm tminfo; struct envlist *p; + f->pending++; + e = getnameinfo((struct sockaddr*)&c->addr, sizeof(c->addr), addr, sizeof(addr), NULL, 0, |