Skip to content

Fix connection leak on conn.ssl or conn.startup failure #698

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

Merged
merged 2 commits into from
Jan 23, 2018
Merged

Fix connection leak on conn.ssl or conn.startup failure #698

merged 2 commits into from
Jan 23, 2018

Conversation

iangudger
Copy link
Contributor

Fixes #697

cn.c.Close()
}
}()

cn.ssl(o)

Choose a reason for hiding this comment

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

It would be ideal if these functions returned errors instead of panicking... but this works as a hot fix. Would leave that to maintainers.

https://github.com/golang/go/wiki/CodeReviewComments#dont-panic

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed. Ideally cn.startup would return an error. But that's a larger change, so I'm fine with this now.

Copy link
Collaborator

@maddyblue maddyblue left a comment

Choose a reason for hiding this comment

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

Is it possible to add a test for this so it doesn't regress?

// cn.ssl and cn.startup panic on error. Make sure we don't leak cn.c.
panicking := true
defer func() {
if panicking {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since err is a named return value I think you can just do if err != nil and drop panicking.

Choose a reason for hiding this comment

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

I thought so, too, initially, but you can't. This defer runs before the recover-defer, so err will still be nil here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ugh. I'm not aware of a project that is more popular and more un-Goish than lib/pq.

cn.c.Close()
}
}()

cn.ssl(o)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed. Ideally cn.startup would return an error. But that's a larger change, so I'm fine with this now.

@maddyblue
Copy link
Collaborator

The build errors aren't your fault: due to the golang tools repo using stuff not present in older Go versions. We should fix that, or more probably just stop testing unsupported versions of Go.

Copy link
Contributor Author

@iangudger iangudger left a comment

Choose a reason for hiding this comment

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

Added test as requested.

Copy link
Collaborator

@maddyblue maddyblue left a comment

Choose a reason for hiding this comment

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

LGTM. Will let it sit for a bit so others can comment if they wish.

@maddyblue maddyblue merged commit 61fe37a into lib:master Jan 23, 2018
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.

3 participants