Skip to content

Update isConnected check to use PQStatus#49

Merged
djones6 merged 1 commit intoKitura:masterfrom
DunnCoding:issue.741
Apr 18, 2018
Merged

Update isConnected check to use PQStatus#49
djones6 merged 1 commit intoKitura:masterfrom
DunnCoding:issue.741

Conversation

@DunnCoding
Copy link
Copy Markdown

No description provided.

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #49 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #49   +/-   ##
=======================================
  Coverage   74.21%   74.21%           
=======================================
  Files           3        3           
  Lines         512      512           
=======================================
  Hits          380      380           
  Misses        132      132
Flag Coverage Δ
#SwiftKueryPostgreSQL 74.21% <0%> (ø) ⬆️
Impacted Files Coverage Δ
...es/SwiftKueryPostgreSQL/PostgreSQLConnection.swift 63.81% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb8d0d2...eb7b504. Read the comment docs.

@DunnCoding DunnCoding requested a review from EnriqueL8 April 16, 2018 12:14
Copy link
Copy Markdown
Contributor

@djones6 djones6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants