Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Daemon: introduce a 5s connect timeout on opening Postgres connections #419

Merged

Conversation

kmoppel-cognite
Copy link
Collaborator

Currently the startup can freeze for long periods on incorrect host info
or in case of real network problems / throttling

Currently the startup can freeze for long periods on incorrect host info
or in case of real network problems / throttling
Comment on lines +348 to 369
if !strings.Contains(strings.ToLower(connStr), "sslmode") {
if strings.Contains(connStr, "postgresql://") { // JDBC style
if strings.Contains(connStr, "?") { // has some extra params already
connStr += "&sslmode=disable" // defaulting to "disable" as Go driver doesn't support "prefer"
} else {
connStr += "?sslmode=disable"
}
} else { // LibPQ style
connStr += " sslmode=disable"
}
}
if !strings.Contains(strings.ToLower(connStr), "connect_timeout") {
if strings.Contains(connStr, "postgresql://") { // JDBC style
if strings.Contains(connStr, "?") { // has some extra params already
connStr += "&connect_timeout=5" // 5 seconds
} else {
//log.Debug("Adding sslmode", libPqConnString+"?sslmode=disable")
db, err = sqlx.Open("postgres", libPqConnString+"?sslmode=disable")
connStr += "?connect_timeout=5"
}
} else { // LibPQ style
db, err = sqlx.Open("postgres", libPqConnString+" sslmode=disable")
connStr += " connect_timeout=5"
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy-Paste detected! :-)

It should be function call, e.g.

connStr = AddDefaultParam(connStr, "sslmode", "disable");
connStr = AddDefaultParam(connStr, "connect_timeout", "5");

Copy link
Contributor

Choose a reason for hiding this comment

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

Guilty as charged sadly :) Tons of refactoring probably required in many places...will one ever find time for that, that is the big question :)

@kmoppel-cognite kmoppel-cognite merged commit b6e6eba into cybertec-postgresql:master Dec 3, 2021
@kmoppel-cognite kmoppel-cognite deleted the add-conn-timeout branch December 3, 2021 14:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants