diff --git a/plugins/psgi/psgi_plugin.c b/plugins/psgi/psgi_plugin.c index 337a2c33..93960531 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -708,15 +708,18 @@ void uwsgi_perl_after_request(struct wsgi_request *wsgi_req) { if (SvTRUE(*harakiri)) wsgi_req->async_plagued = 1; } + // Free the $env hash + SvREFCNT_dec(wsgi_req->async_environ); + // async plagued could be defined in other areas... if (wsgi_req->async_plagued) { uwsgi_log("*** psgix.harakiri.commit requested ***\n"); + // Before we call exit(0) we'll run the + // uwsgi_perl_atexit() hook which'll properly tear + // down the interpreter. goodbye_cruel_world(); } - // clear the env - SvREFCNT_dec(wsgi_req->async_environ); - // now we can check for changed files if (uperl.auto_reload) { time_t now = uwsgi_now(); @@ -850,24 +853,34 @@ void uwsgi_perl_run_hook(SV *hook) { } static void uwsgi_perl_atexit() { + int i; + if (uwsgi.mywid == 0) goto realstuff; - // if hijacked do not run atexit hooks + // if hijacked do not run atexit hooks -- TODO: explain why + // not. if (uwsgi.workers[uwsgi.mywid].hijacked) - return; + goto destroyperl; - // if busy do not run atexit hooks - if (uwsgi_worker_is_busy(uwsgi.mywid)) - return; - - // managing atexit in async mode is a real pain...skip it for now - if (uwsgi.async > 0) - return; realstuff: if (uperl.atexit) { uwsgi_perl_run_hook(uperl.atexit); } + +destroyperl: + + // We must free our perl context(s) so any DESTROY hooks + // etc. will run. + for(i=0;i{'psgix.harakiri'}; + + $env->{'psgix.harakiri.tester'} = bless {} => 'psgix::harakiri::tester'; + my $harakiri = $env->{QUERY_STRING}; + $env->{'psgix.harakiri.commit'} = $harakiri ? 1 : 0; + + return [200, [], [ $harakiri ? "We are about to destroy ourselves\n" : "We will live for another request\n" ]]; +}