summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2009-10-11 21:54:50 +0000
committerStefan Bühler <stbuehler@web.de>2009-10-11 21:54:50 +0000
commitfd13e944278ff86a2c9d1b916a17399bb65db5e8 (patch)
tree4379013a799f16ddaea24a7af414800fc302b878
parenta68a289c75d36965bd43f347679a7cff3e37745b (diff)
downloadlighttpd-git-fd13e944278ff86a2c9d1b916a17399bb65db5e8.tar.gz
mod_fastcgi: restart local procs immediately after they terminated, fix local procs handling
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2639 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--NEWS1
-rw-r--r--src/mod_fastcgi.c48
-rwxr-xr-xtests/mod-fastcgi.t4
3 files changed, 30 insertions, 23 deletions
diff --git a/NEWS b/NEWS
index 4eef4d57..01c109ba 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,7 @@ NEWS
* mod_compress: match partial+full content-type (fixes #1552)
* mod_fastcgi: fix is_local detection, respawn backends if bin-path is set (fixes #897)
* Fix linger-on-close behaviour to avoid rare failure conditions (was r2636, fixes #657)
+ * mod_fastcgi: restart local procs immediately after they terminated, fix local procs handling
- 1.4.23 - 2009-06-19
* Added some extra warning options in cmake and fix the resulting warnings (unused/static functions)
diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c
index 312dfb74..4e3a3355 100644
--- a/src/mod_fastcgi.c
+++ b/src/mod_fastcgi.c
@@ -443,6 +443,20 @@ static void fcgi_host_reset(server *srv, handler_ctx *hctx) {
hctx->host = NULL;
}
+static void fcgi_host_disable(server *srv, handler_ctx *hctx) {
+ plugin_data *p = hctx->plugin_data;
+
+ if (hctx->host->disable_time || hctx->proc->is_local) {
+ hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
+ hctx->proc->state = hctx->proc->is_local ? PROC_STATE_DIED_WAIT_FOR_PID : PROC_STATE_DIED;
+
+ if (p->conf.debug) {
+ log_error_write(srv, __FILE__, __LINE__, "sds",
+ "backend disabled for", hctx->host->disable_time, "seconds");
+ }
+ }
+}
+
static int fastcgi_status_init(server *srv, buffer *b, fcgi_extension_host *host, fcgi_proc *proc) {
#define CLEAN(x) \
fastcgi_status_copy_procname(b, host, proc); \
@@ -2714,7 +2728,6 @@ static int fcgi_restart_dead_procs(server *srv, plugin_data *p, fcgi_extension_h
case PROC_STATE_DIED:
/* local procs get restarted by us,
* remote ones hopefully by the admin */
- if (srv->cur_ts <= proc->disabled_until) break;
if (host->bin_path) {
/* we still have connections bound to this proc,
@@ -2736,6 +2749,8 @@ static int fcgi_restart_dead_procs(server *srv, plugin_data *p, fcgi_extension_h
return HANDLER_ERROR;
}
} else {
+ if (srv->cur_ts <= proc->disabled_until) break;
+
proc->state = PROC_STATE_RUNNING;
host->active_procs++;
@@ -2783,10 +2798,7 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"getsockopt failed:", strerror(errno));
- if (hctx->host->disable_time) {
- hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
- hctx->proc->state = PROC_STATE_DIED;
- }
+ fcgi_host_disable(srv, hctx);
return HANDLER_ERROR;
}
@@ -2799,10 +2811,11 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
"socket:", hctx->proc->connection_name);
}
- if (hctx->host->disable_time) {
- hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
- hctx->proc->state = PROC_STATE_DIED;
- }
+ fcgi_host_disable(srv, hctx);
+ log_error_write(srv, __FILE__, __LINE__, "sdssdsd",
+ "backend is overloaded; we'll disable it for", hctx->host->disable_time, "seconds and send the request to another backend instead:",
+ "reconnects:", hctx->reconnects,
+ "load:", host->load);
fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
buffer_append_string_len(p->statuskey, CONST_STR_LEN(".died"));
@@ -2911,19 +2924,12 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
* for check if the host is back in hctx->host->disable_time seconds
* */
- if (hctx->host->disable_time) {
- hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
- if (hctx->proc->is_local) {
- hctx->proc->state = PROC_STATE_DIED_WAIT_FOR_PID;
- } else {
- hctx->proc->state = PROC_STATE_DIED;
- }
+ fcgi_host_disable(srv, hctx);
- log_error_write(srv, __FILE__, __LINE__, "sdssdsd",
- "backend died; we'll disable it for", hctx->host->disable_time, "seconds and send the request to another backend instead:",
- "reconnects:", hctx->reconnects,
- "load:", host->load);
- }
+ log_error_write(srv, __FILE__, __LINE__, "sdssdsd",
+ "backend died; we'll disable it for", hctx->host->disable_time, "seconds and send the request to another backend instead:",
+ "reconnects:", hctx->reconnects,
+ "load:", host->load);
fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
buffer_append_string_len(p->statuskey, CONST_STR_LEN(".died"));
diff --git a/tests/mod-fastcgi.t b/tests/mod-fastcgi.t
index 880344f2..63c7b152 100755
--- a/tests/mod-fastcgi.t
+++ b/tests/mod-fastcgi.t
@@ -359,7 +359,7 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
- select(undef, undef, undef, 2);
+ select(undef, undef, undef, .2);
$t->{REQUEST} = ( <<EOF
GET /index.fcgi?die-at-end HTTP/1.0
Host: www.example.org
@@ -369,7 +369,7 @@ EOF
ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
- select(undef, undef, undef, 2);
+ select(undef, undef, undef, .2);
$t->{REQUEST} = ( <<EOF
GET /index.fcgi?crlf HTTP/1.0
Host: www.example.org