Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken postgresql connection #223

Closed
wants to merge 7 commits into from
Closed

Fix broken postgresql connection #223

wants to merge 7 commits into from

Conversation

thomastvedt
Copy link
Contributor

@thomastvedt thomastvedt commented Dec 14, 2021

See issue #218

This PR adds max connection lifetime to postgresql db connection. Hopefully this will help with our issue where the auth plugin / mosquitto stops responding after a while (typically 30+ days..)

We're testing this version now in production, we'll test it for a while to verify that it helps on stability. => seems to be working

#218
https://stackoverflow.com/questions/50338338/intermittent-connection-reset-by-peer-sql-postgres

I also bumped
from: github.com/jmoiron/sqlx v1.2.0
to: github.com/jmoiron/sqlx v1.3.4

@iegomez
Copy link
Owner

iegomez commented Jan 13, 2022

Hey, @thomastvedt!

Just reaching out since we're getting close to the time frame you mentioned when Postgres starts becoming unresponsive. Ping me when you get some results from your tests and we'll merge it accordingly.

@thomastvedt thomastvedt marked this pull request as ready for review January 14, 2022 12:18
@thomastvedt
Copy link
Contributor Author

Hey, @thomastvedt!

Just reaching out since we're getting close to the time frame you mentioned when Postgres starts becoming unresponsive. Ping me when you get some results from your tests and we'll merge it accordingly.

Hi @iegomez , seems to be working fine, even with longer periods of inactivity (holidays) 👍. I'll delete the temporary build script / clean up, and you can merge :)

Copy link
Owner

@iegomez iegomez left a comment

Choose a reason for hiding this comment

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

Just left a couple of comments before we merge.

@@ -41,5 +42,7 @@ func OpenDatabase(dsn, engine string, tries int) (*sqlx.DB, error) {
return nil, fmt.Errorf("couldn't ping database %s: %s", engine, err)
}

db.SetConnMaxLifetime(time.Minute)
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe we should make this an option so users may tune it. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, that could be a good idea? Unfortunately I'm not a Go expert, and I'm not sure how to implement that :) Do you want to have a look at it?

Copy link
Owner

Choose a reason for hiding this comment

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

@thomastvedt sorry, I was on vacation and just got back. Sure, I'll do so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thanks 😃

Copy link
Owner

Choose a reason for hiding this comment

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

Terribly sorry for the delay, but here it is, @thomastvedt: #224

backends/db.go Outdated Show resolved Hide resolved
@thomastvedt thomastvedt changed the title Possible fix to broken postgresql connection Fix broken postgresql connection Feb 2, 2022
@iegomez iegomez mentioned this pull request Mar 11, 2022
@thomastvedt
Copy link
Contributor Author

Closing this, replaced by #224

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.

None yet

2 participants