[Twisted-Python] notifyFinish not being called on Windows 10 Twisted 16.4.1
I have been running some tests to check some issue and have seen that notifyFinish is not being called in 16.4.1 This is on Windows 10 using python 2.7.12 Checking back it is not called 16.3.0 but is in 16.2.0 The test uses some sample code from Twisted web in 60 seconds that sets a timer to allow the browser to halt the request by using Escape and make notifyFinish get called. Before I did anything else I thought I would check and see if anyone else was seeing this behaviour. The code I am using is below: from twisted.web.resource import Resource from twisted.web.server import Site, NOT_DONE_YET from twisted.internet import reactor class DelayedResource(Resource): def _delayedRender(self, request): print 'SEND RESPONSE' request.write("Sorry to keep you waiting.") request.finish() def _responseFailed(self, failure, call): print 'RESPONSE FAILED', failure call.cancel() def render_GET(self, request): call = reactor.callLater(10, self._delayedRender, request) request.notifyFinish().addErrback(self._responseFailed, call) return NOT_DONE_YET resource = Resource() print 'RESOURCE', resource resource.putChild("logme", DelayedResource()) factory = Site(resource) print 'FACTORY', factory reactor.listenTCP(8080, factory) reactor.run() -- *John Aherne* *www.rocs.co.uk <http://www.rocs.co.uk>* 020 7223 7567
On 17 Oct 2016, at 08:46, John Aherne <johnaherne@rocs.co.uk> wrote:
I have been running some tests to check some issue and have seen that notifyFinish is not being called in 16.4.1
This is on Windows 10 using python 2.7.12
Checking back it is not called 16.3.0 but is in 16.2.0
The test uses some sample code from Twisted web in 60 seconds that sets a timer to allow the browser to halt the request by using Escape and make notifyFinish get called.
Before I did anything else I thought I would check and see if anyone else was seeing this behaviour.
Yup, this looks like a known issue: https://twistedmatrix.com/trac/ticket/8692 Cory
OK. Thanks for the link. That explains what is going on although I'm not too clear on the details. What I was looking to do was set up an http session and when the browser went away use that a the trigger to expire the session. I didn't just want to set some arbitrary time frame to expire the session but if they just exited the browser or browser tab I could use notifyFinish to pick up the lost connection and I could then expire the session. I have'nt spotted any other info re sessions that would help with this. Thanks John Aherne On Mon, Oct 17, 2016 at 3:13 PM, Cory Benfield <cory@lukasa.co.uk> wrote:
On 17 Oct 2016, at 08:46, John Aherne <johnaherne@rocs.co.uk> wrote:
I have been running some tests to check some issue and have seen that notifyFinish is not being called in 16.4.1
This is on Windows 10 using python 2.7.12
Checking back it is not called 16.3.0 but is in 16.2.0
The test uses some sample code from Twisted web in 60 seconds that sets a timer to allow the browser to halt the request by using Escape and make notifyFinish get called.
Before I did anything else I thought I would check and see if anyone else was seeing this behaviour.
Yup, this looks like a known issue: https://twistedmatrix.com/ trac/ticket/8692
Cory _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- *John Aherne* *www.rocs.co.uk <http://www.rocs.co.uk>* 020 7223 7567
On 17 Oct 2016, at 17:27, John Aherne <johnaherne@rocs.co.uk> wrote:
OK. Thanks for the link.
That explains what is going on although I'm not too clear on the details.
What I was looking to do was set up an http session and when the browser went away use that a the trigger to expire the session.
I didn't just want to set some arbitrary time frame to expire the session but if they just exited the browser or browser tab I could use notifyFinish to pick up the lost connection and I could then expire the session.
I have'nt spotted any other info re sessions that would help with this.
The biggest issue here is that “when the browser goes away” is not a well-defined condition that the server can observe. Browsers will attempt to keep connections open as long as they can, meaning that connection termination may not be observed until quite some time later. Is there any reason that standard cookies (ones that expire at the end of a browser session) + explicit log out aren’t a suitable approach here? Cory
Well since notifyFinish does not do what I was hoping, I'm back to using the standard cookie expire mechanism. I could use javascript to detect idle time, but that's just as arbitrary as expiring cookies. Thanks John Aherne On Mon, Oct 17, 2016 at 5:48 PM, Cory Benfield <cory@lukasa.co.uk> wrote:
On 17 Oct 2016, at 17:27, John Aherne <johnaherne@rocs.co.uk> wrote:
OK. Thanks for the link.
That explains what is going on although I'm not too clear on the details.
What I was looking to do was set up an http session and when the browser went away use that a the trigger to expire the session.
I didn't just want to set some arbitrary time frame to expire the session but if they just exited the browser or browser tab I could use notifyFinish to pick up the lost connection and I could then expire the session.
I have'nt spotted any other info re sessions that would help with this.
The biggest issue here is that “when the browser goes away” is not a well-defined condition that the server can observe. Browsers will attempt to keep connections open as long as they can, meaning that connection termination may not be observed until quite some time later.
Is there any reason that standard cookies (ones that expire at the end of a browser session) + explicit log out aren’t a suitable approach here?
Cory
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- *John Aherne* *www.rocs.co.uk <http://www.rocs.co.uk>* 020 7223 7567
Having read the irc log a few times I'm still not clear what is meant to happen. I can't see under what circumstances notifyFinish will return a Failure. John Aherne On Mon, Oct 17, 2016 at 5:48 PM, Cory Benfield <cory@lukasa.co.uk> wrote:
On 17 Oct 2016, at 17:27, John Aherne <johnaherne@rocs.co.uk> wrote:
OK. Thanks for the link.
That explains what is going on although I'm not too clear on the details.
What I was looking to do was set up an http session and when the browser went away use that a the trigger to expire the session.
I didn't just want to set some arbitrary time frame to expire the session but if they just exited the browser or browser tab I could use notifyFinish to pick up the lost connection and I could then expire the session.
I have'nt spotted any other info re sessions that would help with this.
The biggest issue here is that “when the browser goes away” is not a well-defined condition that the server can observe. Browsers will attempt to keep connections open as long as they can, meaning that connection termination may not be observed until quite some time later.
Is there any reason that standard cookies (ones that expire at the end of a browser session) + explicit log out aren’t a suitable approach here?
Cory
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- *John Aherne* *www.rocs.co.uk <http://www.rocs.co.uk>* 020 7223 7567
On Oct 18, 2016, at 12:29 AM, John Aherne <johnaherne@rocs.co.uk> wrote:
Having read the irc log a few times I'm still not clear what is meant to happen.
I can't see under what circumstances notifyFinish will return a Failure.
The difference between firing with None and firing with a Failure is extremely subtle. If the client connection terminates "before it's ready" then you'll get an Failure, but this is fairly fuzzily defined in terms of application-level semantics. A connection that is "not ready" to terminate might be one that has outstanding data to send to the client which the client doesn't receive, or a connection which has only partially received a request. There are other low-level details of the socket which might also be relevant (for example, I think you might also get this if the client neglects to send a CLOSE_ALERT TLS message). For most applications, the difference between "failure" and "success" in this case just isn't very interesting. As Corey identified earlier in the thread though, _also_ a bug where it isn't being called all the time when we expect it. As the ticket said though, you can try to work around this by just calling resumeProducing() unconditionally at the beginning of your request processing... -glyph
participants (3)
-
Cory Benfield
-
Glyph Lefkowitz
-
John Aherne