Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Try postgres reconnect on database connection lost #339

Merged
merged 4 commits into from
Apr 20, 2018

Conversation

jklimke
Copy link

@jklimke jklimke commented Apr 9, 2018

This pull request should cause the postgres auth adapter to try to reestablish a connection if a query was rejected because of a bad connection.

I should be a first approach to fix #269 . This could be implemented a lot more suffisticated (e.g., the connection retries could be limited), but this should work for now.

@@ -182,6 +182,12 @@ int be_pg_getuser(void *handle, const char *username, const char *password, char

if (PQresultStatus(res) != PGRES_TUPLES_OK) {
_log(LOG_DEBUG, "%s\n", PQresultErrorMessage(res));
if(PQstatus(conf->conn) == CONNECTION_BAD){
Copy link
Contributor

Choose a reason for hiding this comment

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

What if this was executed prior to running a query - will that still work?

Copy link
Author

@jklimke jklimke Apr 9, 2018

Choose a reason for hiding this comment

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

I am not sure if i understand your comment correctly. How should that be possible at that position ? I understand that all postgres queries are currently performed synchronously. That means that the query has been finished (not sucessfully) when this piece of code comes into play.

On line 174 there is a check if the database connection has been initialized

if (!conf || !conf->userquery || !username || !*username)
		return BACKEND_DEFER;

That means a connection should exist a the moment and a query has finished

Copy link
Contributor

Choose a reason for hiding this comment

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

I've looked at the source, and you are of course correct.

@jklimke
Copy link
Author

jklimke commented Apr 20, 2018

Is there still a reason left why this can't be merged so far ?

@jasiek
Copy link
Contributor

jasiek commented Apr 20, 2018

I think this is good to go - but I don't have the commit bit.

@jpmens
Copy link
Owner

jpmens commented Apr 20, 2018

As @jasiek has reviewed this, I will press the button. Thank you for your work, gentlement!

@jpmens jpmens merged commit 2eeee36 into jpmens:master Apr 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PostgreSQL backend should attempt to reconnect to the database
3 participants