-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unregister from the reactor when connection is going to be closed. #5
Conversation
Otherwise we still may have incoming events from the socket
This bug is reproducible randomly, when having several concurrent connections to PostgreSQL and closing them |
I see how this can be happening, still working on a test case that will reproduce in in 100% of the cases. Could you try with Twisted HEAD? Specifically this bug: http://twistedmatrix.com/trac/ticket/4539 has caused some problems in txpostgres, I wonder if a fixed version would also fix this issue. Probably not, but maybe worth a try. The patches look good and I'll pull them shortly, although I want to have a test case ready first. Thanks! |
Thanks for looking on that, actually I was using pretty new version of Twisted, I'm almost always following trunk. It is 2 weeks old, https://github.com/smira/twisted/. |
Oh, ok, thanks. Should have this wrapped up before the end of the weekend. |
Instead, rely on the closed property to determine whether it is safe to call poll() on the pollable object. That's more explicit than relying on the pollables being None and more correct, too, because removing the references to the pollable immediately after closing it would lead to errors such as reported in issue #5. It is not certain that this commit fixes the issue, but it definitely is a step forward from the code quality standpoint.
Ugh, that took a while... I didn't manage to reproduce your issue, but while I was investigating this one, another bug surfaced: #6. I committed a partial fix for it and a side effect is that pollable() will no longer be set to None after the connection is closed. If you're using epoll you might be affected by #6 but perhaps this issue got fixed by my last change. Could you try again? |
* upstream/master: Add support for NOTIFY events. Explicitly call connectionLost when closing the connection. Light refactoring of tests. Do not set the pollables to None immediately before closing them. Add docstring and some comments to a test case. Conflicts: txpostgres/txpostgres.py
generate spurious Deferreds.
It took me a while to do testing and fixes with the new version, but it seems to be more stable than previous ones. Summary of changes:
|
Thanks for that! I pushed the changes from 1) and 2) + a unit test. I like the idea of 3) as I just noticed that closing the connection while listening for NOTIFY generates these annoying "unhandled error" messages. I think I'll follow your suggestion and split poll() into two methods. I try to avoid Python asserts in code, so I might change that into a ValueError. I guess that since you call _poll() only from _continue_polling() I'm just going to inline it. Oh, and the method name will have to change, since I try to follow Twisted's standard of using camel case (even though I hate it). Thanks again and I'll try to push the last fix faster then the previous time :) |
I just pushed the split of poll() into poll() and continuePolling(). I hope this will finally resolve this issue. Thank you for your analysis and patches, I think things are in a quite better shape now. |
I did some testing with https://github.com/oberstet/txpostgres/blob/testing/testing/txpostgres_error.py 2 cases: a) correct database password, should fail on "select * from nonexistent" The latest give me tracebacks on both: https://gist.github.com/1353252 The latest gives me traceback only on b), and works for a): |
Thanks a lot, all my tests are working fine right now! I'm closing this pull request, I have one more change related to stack overflow under certain circumstances, but that deserves new pull request ) |
Great to hear that your testing proved fine now! Don't hesitate to open a separate issue for the stack overflow. Thanks! |
Otherwise we still may have incoming events from the socket, but there's no handler for them (self.pollable() becomes None).