• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item5729: a redirect quits cgi process before finishing the twiki object

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Engine   Normal Waiting for Feedback TWiki:Main/MichaelDaum n/a  

Edit Form Data

Reported By:
Applies To:
Current State:
Waiting For:
Target Release:
Released In:


I just found the following. Given there's a scheduled redirect. Then printing out the complete page to STDOUT will immediately send the page to the browser and quit the cgi process without twiki having a chance to clean up using the finish() methods. You will observe that the called method in UI.pm will not return.

That obviously has got a series of consequences, e.g. this is a memory leak. In addition, the cgi session object is not flushed to disk. Not flushing the cgi session will result in session variables getting lost or session variables not being deleted.

Can anybody confirm this?

-- TWiki:Main/MichaelDaum - 23 Jun 2008

I'm pretty sure you are right. I'm also reasonably sure that the TWiki Standalone work will eliminate this legacy.

-- TWiki:Main.SvenDowideit - 24 Jun 2008

even nastier are the number of Plugins that take return die or other shortcuts to exit. Too much assumption that its a single exec per request CGI.

-- TWiki:Main.SvenDowideit - 25 Jun 2008

Honestly they could, if they just finished the session object regularly. For instance, the RedDotPlugin is doing its own redirect stuff ... based on the content of session variables. Just before it redirects the cgi query, it clears the value of the session variable ... but that won't get flushed to disk as the official redirect will happen at a phase of the code where the session does not get finished and thus never flushed to disk. So the only solution for RedDot is to finish() the twiki object itself and exit.

-- TWiki:Main.MichaelDaum - 26 Jun 2008

Not sure I fully understand the problem here. A CGI::redirect does not of itself quit the calling process; it simply prints a redirect header on STDOUT. The print usually isn't flushed until the process is quit by a subsequent exit. So, if you perform a redirect and then immediately exit without an intervening finish then yes, there is a problem. A quick review of the TWiki core code suggests that all redirects have a finish call before the exit, however; unless you know of a specific counter-example?

Users of TWiki::Func::redirectCgiQuery will be caught by this, if they have not explicitly called finish. I was aware of this problem but didn't move the finish and exit into TWiki::redirect because that would have broken the pre-existing spec of TWiki::Func::redirectCgiQuery.

Note that plugins that die or throw are already in good shape because TWiki::UI handles the finish.

-- TWiki:Main.CrawfordCurrie - 27 Jun 2008

The way I discovered this is that the session object was not flushed to disk on a redirect, which is a natural consequence of the finish() methods not being called. Poor-man's-debugging (adding print STDERR) showed that as soon as the CGI::redirect was print to STDOUT, the method called in TWiki::UI did not return and thus the finish() call at the end did not get called. Further debugging lent me to the conclusion that all of the process was gone already.

Can anybody reproduce this behavior?

-- TWiki:Main.MichaelDaum - 30 Jun 2008

I changed UI.pm

>     print STDERR "run starts for method $method\n";
>     print STDERR "run finished for method $method\n";
in order to see the effect. I surfed some pages. But all messages (even in redirect cases) are paired in the sense
run starts for method CODE(0xb6fba0)
run finished for method CODE(0xb6fba0)
run starts for method CODE(0xb71070)
run finished for method CODE(0xb71070)

Can you describe in what redirect situation this happens? Are there special redirects where this happens? And what's a "scheduled" redirect?

-- TWiki:Main.ChristianLudwig - 30 Jun 2008

Would a sleep work? Waiting 0.2 sec on a redirect is not noticeable by users

-- TWiki:Main.PeterThoeny - 07 Jul 2008

TWiki:Codev.GeorgetownReleaseMeeting2008x07x21 decided to downgrade to normal with the comment that the conclusion in the report is probably not correct.

-- TWiki:Main.KennethLavrsen - 22 Jul 2008

Summary a redirect quits cgi process before finishing the twiki object
ReportedBy TWiki:Main.MichaelDaum

SVN Range TWiki-5.0.0, Sun, 01 Jun 2008, build 16865
AppliesTo Engine

Priority Normal
CurrentState Waiting for Feedback
WaitingFor TWiki:Main/MichaelDaum

TargetRelease n/a

Edit | Attach | Watch | Print version | History: r10 < r9 < r8 < r7 < r6 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r10 - 2008-07-22 - KennethLavrsen
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback