Inconsistency in the IOStream.closed method #455

Open
oyerli opened this Issue Feb 3, 2012 · 2 comments

Projects

None yet

2 participants

@oyerli
Contributor
oyerli commented Feb 3, 2012

Hi,
The fix in the commit 501f596 caused a problem in my async web server application:
I expect IOStream.closed method to return true AS SOON AS the close_callback is called. (This was the previous behaviour since it was not waiting for the pending callbacks). Now, the closed() method returns true but the close_callback waits the pending callbacks to finish. Hence the connection is not actually closed. Is it the intended behaviour?

I expect the closed() method to return true after all pending callbacks finished AND the close_callback is called. Otherwise we cannot know if the connection is actually closed.

@bdarnell
Member

The current behavior is as intended: IOStream.closed() returns true if the underlying network connection has been closed, but there may be some time between that event and the close_callback (if there are pending operations that can be satisfied from buffers). If closed() did not return true until after close_callback was called, there would be no way to detect whether you were in this intermediate state.

@oyerli
Contributor
oyerli commented Feb 20, 2012

If it is the intended behaviour then there is a problem in the chatdemo application. I know it, since I am using a slightly modified version of chatdemo in production.

In chatdemo, if a user closes the connection at the same time a message is arrived, on_new_messages is called and the if condition in that method prevents calling self.finish. Hence the on_connection_close is called later and tries to remove that callback from the already emptied set (since when a new message arrives we empty the set). This causes a KeyError.

Can you suggest a fix?

@bdarnell bdarnell added the iostream label Jul 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment