Re: Race when saving sessions
"Jacob Smullyan" <[email protected]> Mon, 22 Oct 2007 12:03:52 -0400
| Newsgroups | gmane.comp.web.skunkweb |
|---|---|
| Message-ID | <[email protected]> |
--===============0516461979== Content-Type: multipart/alternative; boundary="----=_Part_18372_9530619.1193069032564" ------=_Part_18372_9530619.1193069032564 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline The skunkweb session behavior of saving the session *after* the response is sent is the problem here. It breaks when the client responds very quickly, as in the case of a redirect. The best solution, IMO, is simply to save the session before you send the response -- either explicitly in application code or in a hook, as you've done (and you are right that PreSendResponse is a better name). You can probably get away with only doing it in application code when you know you are redirecting, but the hook solution is admittedly cleaner. I'm working on sessions (sporadically) for skunkweb 4 now, and this problem won't occur there; sessions will always be saved before the response. On 10/22/07, Nick Murtagh <[email protected]> wrote: > > Hi, > > I've noticed some strange behaviour in SkunkWeb that I finally tracked > down to a race when saving sessions. Here's what should happen: > > Skunkweb Process 1: Load Session > Skunkweb Process 1: Save Session > Skunkweb Process 1: Redirect > Skunkweb Process 2: Load Session > Skunkweb Process 2: Save Session > > Here's what happens some of the time: > > Skunkweb Process 1: Load Session > Skunkweb Process 1: Redirect > Skunkweb Process 2: Load Session > Skunkweb Process 2: Save Session > Skunkweb Process 1: Save Session > > Oops! > > I resolved it by adding another KeyedHook to > Services/requestHandler/requestHandler.py > > PreRequest=KeyedHook() > > In _sendResponse I call this hook before send_it_all: > > try: > PreRequest(Configuration.job, requestData, sessionDict) > except: > logException() > > And finally in Services/sessionHander/__init__.py I replaced: > > rr.PostRequest.addFunction(Session.saveSession, allweb) > > with > > rr.PreRequest.addFunction(Session.saveSession, allweb) > > > This fixes the problem for me, but there are a couple of issues: > > - Is this the correct fix? > > - I think the hook should probably be called something other than > PreRequest, perhaps PreSendResponse? Any suggestions? > > -- > Nick Murtagh <[email protected]> > go2web Ltd., Harbour House, Harbour Road, Howth, Dublin 13 > http://www.go2.ie/ - Phone +353-(0)1-839-5432 - Fax +353-(0)1-839-5439 > Registered in Ireland: No. 327376 > Registered address: 53 Thormanby Lawns, Howth, Dublin 13 > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Skunkweb-list mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/skunkweb-list > -- Jacob Smullyan office: 212/669-3230 mobile: 917/576-5274 ------=_Part_18372_9530619.1193069032564 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline The skunkweb session behavior of saving the session *after* the response is sent is the problem here. It breaks when the client responds very quickly, as in the case of a redirect. The best solution, IMO, is simply to save the session before you send the response -- either explicitly in application code or in a hook, as you've done (and you are right that PreSendResponse is a better name). You can probably get away with only doing it in application code when you know you are redirecting, but the hook solution is admittedly cleaner. <br><br>I'm working on sessions (sporadically) for skunkweb 4 now, and this problem won't occur there; sessions will always be saved before the response. <br><br><div><span class="gmail_quote">On 10/22/07, <b class="gmail_sendername"> Nick Murtagh</b> <<a href="mailto:[email protected]">[email protected]</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br> <br>I've noticed some strange behaviour in SkunkWeb that I finally tracked<br>down to a race when saving sessions. Here's what should happen:<br><br> Skunkweb Process 1: Load Session<br> Skunkweb Process 1: Save Session <br> Skunkweb Process 1: Redirect<br> Skunkweb Process 2: Load Session<br> Skunkweb Process 2: Save Session<br><br>Here's what happens some of the time:<br><br> Skunkweb Process 1: Load Session<br> Skunkweb Process 1: Redirect <br> Skunkweb Process 2: Load Session<br> Skunkweb Process 2: Save Session<br> Skunkweb Process 1: Save Session<br><br>Oops!<br><br>I resolved it by adding another KeyedHook to<br>Services/requestHandler/requestHandler.py <br><br> PreRequest=KeyedHook()<br><br>In _sendResponse I call this hook before send_it_all:<br><br> try:<br> PreRequest(Configuration.job, requestData, sessionDict)<br> except:<br> logException()<br> <br>And finally in Services/sessionHander/__init__.py I replaced:<br><br> rr.PostRequest.addFunction(Session.saveSession, allweb)<br><br>with<br><br> rr.PreRequest.addFunction(Session.saveSession, allweb)<br><br><br> This fixes the problem for me, but there are a couple of issues:<br><br> - Is this the correct fix?<br><br> - I think the hook should probably be called something other than<br> PreRequest, perhaps PreSendResponse? Any suggestions? <br><br>--<br>Nick Murtagh <<a href="mailto:[email protected]">[email protected]</a>><br>go2web Ltd., Harbour House, Harbour Road, Howth, Dublin 13<br><a href="http://www.go2.ie/">http://www.go2.ie/</a> - Phone +353-(0)1-839-5432 - Fax +353-(0)1-839-5439 <br>Registered in Ireland: No. 327376<br>Registered address: 53 Thormanby Lawns, Howth, Dublin 13<br><br>-------------------------------------------------------------------------<br>This SF.net email is sponsored by: Splunk Inc. <br>Still grepping through log files to find problems? Stop.<br>Now Search log events and configuration files using AJAX and a browser.<br>Download your FREE copy of Splunk now >> <a href="http://get.splunk.com/">http://get.splunk.com/ </a><br>_______________________________________________<br>Skunkweb-list mailing list<br><a href="mailto:[email protected]">[email protected]</a><br><a href="https://lists.sourceforge.net/lists/listinfo/skunkweb-list"> https://lists.sourceforge.net/lists/listinfo/skunkweb-list</a><br></blockquote></div><br><br clear="all"><br>-- <br>Jacob Smullyan<br>office: 212/669-3230<br>mobile: 917/576-5274<br> ------=_Part_18372_9530619.1193069032564-- --===============0516461979== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ --===============0516461979== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Skunkweb-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/skunkweb-list --===============0516461979==--