-
Notifications
You must be signed in to change notification settings - Fork 73
Fixed error handling when getting a connection. #115
Conversation
Nice catch. It's bug indeed, but of a different kind. The thing is that That's why I use
I also strive to cover all bugs with unittests. Can you please write one for this issue? I guess it would be enough to close conn's file descriptor to simulate server restart. Thanks. |
Explored this for a bit and it seems a bit more complicated. If Connection.ping dies in Pool._operate if will do a Pool.putconn in all cases but one - If a file descriptor is closed another error happens - Checking how restarts work I found psycopg#196 but restarting the server still doesn't mark the connection as closed properly (at least on osx using psycopg2 2.6.1). Once that happens connects are never recycled. Connections to a host also fail in retrying as Connection._io_callback fails, retry loop is not triggered as the exception is added to the future and the query fails - this time the connection is correctly marked as closed and is recycled. Am I missing something? |
OK, lets take it one thing in a time. @jchumnanvech original bug is an issue with incorrect API call. It's trivial and should be fixed. But the bug itself surfaced another issue - unittest do not properly verify connectivity issues handling. Regarding psycopg#196. It was fixed back then when I complained about it and is still working as of psycopg2 2.6.1 on my Ubunutu 14.04. Probably it's OSX specific issue. @friedcell, I suggest you reopen the ticket on psycopg2 tracker. Now, @friedcell discovered another bug: @friedcell, regarding your last paragraph - I fail to understand what you are trying to say (that's probably me :) ). Can you please open another issue for this and we'll continue to analyze it there? (Some code that catches concrete failure scenarios would really help). |
I'll open another issue for reconnection issues - I have tests for that but need to do some more testing on Ubuntu. I don't yet have tests for double |
Looks like server restarts can be simulated pretty well with the following:
The real server restart causes the following:
The next step is to incorporate connection killing into unittests, see where it fails and continue from there. |
I think I can tinker it. |
I got different errors on OSX - my biggest problem was the fact that psycopg2 does not report the connections as closed. Solved double putconn with a simple |
@friedcell, I finally see what you are saying - the retrial code runs only when Something to work on... Thanks for discovering this. |
With async code, shutting socket down for writes, does not set
And the result is:
|
I fixed all of, hopefully, it in my master branch. Guys, can you try this version: https://github.com/haizaar/momoko? At the end, shutting down sockets, did not work - this somehow augments If you run tests, make sure to run |
Guys, does anyone has any experience with Travis CI? for some reason my proxy tests fail when run on Travis - can't force psycopg2 into connecting through TCP to my proxy. Here is the failing build - https://travis-ci.org/haizaar/momoko/builds/77378307 (pulls from my master). |
Travis fixed. I've merged the code to master. Feedback is welcome. |
Tested in all scenarios that were failing for me before - works perfectly now. Sorry for the delay, fell into a zone where normal things don't happen very often. |
Excellent. I'll release 2.2.0 later this week.
|
Right now we are encountering a bug when someone resets the postgres-db service. The connections become stale. When psycopg2 Error is thrown set_exc_info with error throws another exception which causes the connection to not be put back in the connection pool (line 560 is not executed because line 559 blows up). Its in the the tornado concurrent exception traceback logger.
It is trying to pass in the error into
self.formatted_tb = traceback.format_exception(*exc_info) and exc_info is only 1 parameter and it excepts 3
This is in concurrent.py line 113
Changing it to set exception seems to make it work.