summaryrefslogtreecommitdiff
path: root/t/perl/test_harakiri.psgi
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2014-11-10 18:53:10 +0000
committerÆvar Arnfjörð Bjarmason <avarab@gmail.com>2014-11-10 18:57:52 +0000
commit7ef33950c5fbf07eb1b8b9ac369a17adfd4ca424 (patch)
tree4e7be01405dd6c9f14dc811e363a4a07a78dd8bd /t/perl/test_harakiri.psgi
parentdd0688ee84a1d3f2d48a41225626a0c3d7741615 (diff)
downloaduwsgi-7ef33950c5fbf07eb1b8b9ac369a17adfd4ca424.tar.gz
psgi: Ensure that we call any DESTROY hooks on psgix.harakiri.commit
Before this we'd just exit(0) and let the OS clean up after us, but e.g. with post-buffering=1 we'll end up with a temporary file in /tmp that we won't clean up when we exit unless DESTROY is called. This resulted in us leaking files in /tmp if we ever had a request where the last request before a harakiri was a POST request with a body we'd buffer to /tmp. We'd have similar leaks in any user-defined code that required DESTROY to run. Aside from this I'm still not very comfortable with what this whole code here in psgi_plugin.c and psgi_loader.c is doing when managing the interpreter(s). It: * Doesn't consistently call PERL_SET_CONTEXT() as described in "perldoc perlembed". * Nothing calls PERL_SYS_TERM() either. * Should we be calling uwsgi_perl_free_stashes() here too? To test this: UWSGI_PROFILE=psgi python uwsgiconfig.py --build ./uwsgi --master --http-socket localhost:1234 --psgi t/perl/test_harakiri.psgi Then elsewhere: curl 'localhost:1234?0' curl 'localhost:1234?1' Both of those should emit "Calling DESTROY".
Diffstat (limited to 't/perl/test_harakiri.psgi')
-rw-r--r--t/perl/test_harakiri.psgi19
1 files changed, 19 insertions, 0 deletions
diff --git a/t/perl/test_harakiri.psgi b/t/perl/test_harakiri.psgi
new file mode 100644
index 00000000..7680944a
--- /dev/null
+++ b/t/perl/test_harakiri.psgi
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+{
+ package psgix::harakiri::tester;
+ sub DESTROY { print STDERR "$$: Calling DESTROY\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" ]];
+}