-
Notifications
You must be signed in to change notification settings - Fork 922
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
Conversation
cn.c.Close() | ||
} | ||
}() | ||
|
||
cn.ssl(o) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this 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.
There was a problem hiding this 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.
Fixes #697