summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstbuehler <stbuehler@152afb58-edef-0310-8abb-c4023f1b3aa9>2009-10-25 17:32:35 +0000
committerstbuehler <stbuehler@152afb58-edef-0310-8abb-c4023f1b3aa9>2009-10-25 17:32:35 +0000
commit0d2127c11b84fd98b2f09bb1304a84b393171b7a (patch)
treee2c69fc3cd575f9cf17da4ae64a785a4e9099bc7
parent5462f9f54893ef54c6c992a90b36a49e045cbc41 (diff)
downloadlighttpd-0d2127c11b84fd98b2f09bb1304a84b393171b7a.tar.gz
Fix mod_cgi hang on "crash-before-header-sent" bug
* connection gets killed by timeout git-svn-id: svn://svn.lighttpd.net/lighttpd/trunk@2674 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--NEWS1
-rw-r--r--src/mod_cgi.c12
2 files changed, 11 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index e1fe119a..ff70ba1e 100644
--- a/NEWS
+++ b/NEWS
@@ -149,6 +149,7 @@ NEWS
* Don't print ssl error if client didn't support TLS SNI
* Reopen out stream in X-Rewrite (fixes #1678)
* Remove joblist thread, don't use timed pops for async queues
+ * Fix mod_cgi hang on "crash-before-header-sent" bug
- 1.5.0-r19.. -
* -F option added for spawn-fcgi
diff --git a/src/mod_cgi.c b/src/mod_cgi.c
index 77a443fd..5e02826a 100644
--- a/src/mod_cgi.c
+++ b/src/mod_cgi.c
@@ -328,6 +328,11 @@ static int cgi_demux_response(server *srv, connection *con, plugin_data *p) {
con->http_status = 502; /* Bad Gateway */
return -1;
case PARSE_NEED_MORE:
+ if (sess->rb->is_closed) {
+ /* backend died before sending a header */
+ con->http_status = 502; /* Bad Gateway */
+ return -1;
+ }
return 0;
case PARSE_SUCCESS:
con->http_status = p->resp->status;
@@ -560,6 +565,7 @@ static handler_t cgi_handle_fdevent(void *s, void *ctx, int revents) {
/* kill all connections to the cgi process */
fdevent_event_del(srv->ev, sess->sock);
+ joblist_append(srv, con);
}
return HANDLER_FINISHED;
@@ -615,7 +621,7 @@ static handler_t cgi_handle_err_fdevent(void *s, void *ctx, int revents) {
cgi_session *sess = ctx;
connection *con = sess->remote_con;
- if (revents & FDEVENT_IN) {
+ if (revents & (FDEVENT_IN | FDEVENT_HUP)) {
switch (srv->network_backend_read(srv, con, sess->sock_err, sess->rb_err)) {
case NETWORK_STATUS_CONNECTION_CLOSE:
fdevent_event_del(srv->ev, sess->sock_err);
@@ -1130,8 +1136,10 @@ TRIGGER_FUNC(cgi_trigger) {
#if 0
log_error_write(srv, __FILE__, __LINE__, "sd", "(debug) cgi exited fine, pid:", p->cgi_pid.ptr[ndx]);
#endif
+ } else if (WIFSIGNALED(status)) {
+ log_error_write(srv, __FILE__, __LINE__, "sdsd", "cgi signaled, pid:", p->cgi_pid.ptr[ndx], ", signal", WTERMSIG(status));
} else {
- log_error_write(srv, __FILE__, __LINE__, "s", "cgi died ?");
+ log_error_write(srv, __FILE__, __LINE__, "sdsd", "cgi died, pid:", p->cgi_pid.ptr[ndx], ", status", status);
}
cgi_pid_del(srv, p, p->cgi_pid.ptr[ndx]);