Update isConnected check to use PQStatus#49
Update isConnected check to use PQStatus#49djones6 merged 1 commit intoKitura:masterfrom DunnCoding:issue.741
Conversation
Codecov Report
@@ Coverage Diff @@
## master #49 +/- ##
=======================================
Coverage 74.21% 74.21%
=======================================
Files 3 3
Lines 512 512
=======================================
Hits 380 380
Misses 132 132
Continue to review full report at Codecov.
|
djones6
left a comment
There was a problem hiding this comment.
This fixes the check so that we are asking libpq for the status, and does eventually give the right answer, and is an improvement which is worth making.
Unfortunately, it turns out that libpq does not do anything more than look up a flag when you call this: if the connection hasn't been used since it died, this will still answer CONNECTION_OK. The consequence is that the user will get a connection which claims to be OK, but will fail when they try to use it. After that point, it will correctly answer that it is dead.
One way that we might be able to make Postgres connections behave nicely would be something like:
- attempt execution of a query
- if the attempt fails, check
PQstatus:- if the connection wasn't dead, just return the error as normal
- if it is dead, attempt to replace our libpq connection with a new one. If this succeeds, execute the query again, otherwise, return the original error.
There are various issues with this which need more thought, and it's way out of scope for this PR.
No description provided.