mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-08-29 02:05:38 +00:00
Merge pull request #772 from avar/avar/psgi-call-DESTROY-also-on-harakiri
psgi: Ensure that we call any DESTROY hooks on psgix.harakiri.commit
This commit is contained in:
+25
-12
@@ -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<uwsgi.threads;i++) {
|
||||
PERL_SET_CONTEXT(uperl.main[i]);
|
||||
|
||||
// Destroy the PerlInterpreter, see "perldoc perlembed"
|
||||
perl_destruct(uperl.main[i]);
|
||||
perl_free(uperl.main[i]);
|
||||
}
|
||||
PERL_SYS_TERM();
|
||||
free(uperl.main);
|
||||
}
|
||||
|
||||
static uint64_t uwsgi_perl_rpc(void *func, uint8_t argc, char **argv, uint16_t argvs[], char **buffer) {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
{
|
||||
package psgix::harakiri::tester;
|
||||
sub DESTROY { print STDERR "$$: Calling DESTROY\n" }
|
||||
}
|
||||
|
||||
uwsgi::atexit(
|
||||
sub {
|
||||
print STDERR "$$: Calling the atexit hook\n";
|
||||
}
|
||||
);
|
||||
|
||||
sub {
|
||||
my $env = shift;
|
||||
|
||||
die "PANIC: We should support psgix.harakiri here" unless $env->{'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" ]];
|
||||
}
|
||||
Reference in New Issue
Block a user