From 11b0e431f4cce16a08a56dfd56fa33fdca0d0e7d Mon Sep 17 00:00:00 2001 From: Unbit Date: Wed, 11 Feb 2015 11:32:33 +0100 Subject: [PATCH] attempt to fix #833 --- plugins/psgi/psgi_plugin.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/plugins/psgi/psgi_plugin.c b/plugins/psgi/psgi_plugin.c index e27f7ccb..53b68b2d 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -684,6 +684,19 @@ void uwsgi_perl_after_request(struct wsgi_request *wsgi_req) { // before the environ is set up. if (!wsgi_req->async_environ) return; + // we need to restore the context in case of multiple interpreters + struct uwsgi_app *wi = &uwsgi_apps[wsgi_req->app_id]; + if (uwsgi.threads < 2) { + if (((PerlInterpreter **)wi->interpreter)[0] != uperl.main[0]) { + PERL_SET_CONTEXT(((PerlInterpreter **)wi->interpreter)[0]); + } + } + else { + if (((PerlInterpreter **)wi->interpreter)[wsgi_req->async_id] != uperl.main[wsgi_req->async_id]) { + PERL_SET_CONTEXT(((PerlInterpreter **)wi->interpreter)[wsgi_req->async_id]); + } + } + // dereference %env SV *env = SvRV((SV *) wsgi_req->async_environ); @@ -731,6 +744,19 @@ void uwsgi_perl_after_request(struct wsgi_request *wsgi_req) { } } + // restore main interpreter if needed + if (uwsgi.threads > 1) { + if (((PerlInterpreter **)wi->interpreter)[wsgi_req->async_id] != uperl.main[wsgi_req->async_id]) { + PERL_SET_CONTEXT(uperl.main[wsgi_req->async_id]); + } + } + else { + if (((PerlInterpreter **)wi->interpreter)[0] != uperl.main[0]) { + PERL_SET_CONTEXT(uperl.main[0]); + } + } + + } int uwsgi_perl_magic(char *mountpoint, char *lazy) {