From bad07a8520bc2e9f384eebd83fb82358e43c6577 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 e241135f..8735777a 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -637,6 +637,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); @@ -684,6 +697,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) {