Browse Source

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
svn/tags/lighttpd-1.4.24
Stefan Bühler 12 years ago
parent
commit
fd13e94427
  1. 1
      NEWS
  2. 48
      src/mod_fastcgi.c
  3. 4
      tests/mod-fastcgi.t

1
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)

48
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"));

4
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

Loading…
Cancel
Save