crystal-pg icon indicating copy to clipboard operation
crystal-pg copied to clipboard

Reset connection

Open ysbaddaden opened this issue 8 years ago • 2 comments

Could we had a mecanism to detect a connection issue and to reset the connection? Maybe wrapping the thrown socket Errno as PQ::SocketError and adding PQ::Connection#reset and PG::Connection#reset methods?

This is useful when a connection gets staled or broken, which happens regularly on the Heroku free plans. I used to catch PG::Error exceptions, call LibPQ.reset once before retrying, as long as the reset didn't fail. Namely those two patches: https://github.com/ysbaddaden/frost/commit/184642ce4f2b3f939145476e89ee245a1caa6d11 and https://github.com/ysbaddaden/frost/commit/b3c15869884e82705e3d30e7b28ae7160ea36a0e

ysbaddaden avatar May 12 '16 10:05 ysbaddaden

Adding those methods and wrapping does sound like a good solution. Is there a particular Errno that you see when the connection is dropped? I'll get to this sometime soon, but would accept a patch from anyone that wants to do this.

Related, it would also be possible to try to reconnect in the driver itself, but we wouldn't want to spin trying to reconnect forever. Maybe either one retry or exponential backoff. Not sure if that belongs in the driver or not though.

will avatar May 16 '16 20:05 will

Is this solved by using the Crystal DB connection or does the problem still exist?

benoist avatar Mar 07 '17 08:03 benoist