-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
pgwire: fix memory account leak #22448
Conversation
Want unique_ptr. Release note: None
Good catch.
I feel you! Reviewed 1 of 1 files at r1. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file):
For good measure, add an explanatory comment that these Closes are not needed any more once the defer underneath has been set up, because the session then takes ownership of the thing. Comments from Reviewable |
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks pending. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file):
Seems more natural to do this in the caller, we just have to make Comments from Reviewable |
PS No test? Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks pending. Comments from Reviewable |
A test would probably be complicated to write... We need a connection that fails at just the right time... I think the only hope for catching such things is a high-level test that bombards a server with connections. Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Starting to do this sort of thing in the callers generally seems like a bad idea to me. The sane contract is callee takes responsibility. The moment control flow is returned to the caller shouldn't matter as far as the resource is concerned. If the callee wants to pass ownership along to an async fella, it's her business. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file): Previously, knz (kena) wrote…
ummm sounds like it'd be a pretty rando comment. On which line would I even put it? Comments from Reviewable |
Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file): Previously, andreimatei (Andrei Matei) wrote…
All right, carry on. Comments from Reviewable |
Let me push back on the difficulty: a test could manually create a Review status: all files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Ok, at the top of this function, pkg/sql/pgwire/v3.go, line 351 at r1 (raw file):
I think you missed a Comments from Reviewable |
PS I can understand not wanting to test in this soon to be obsolete code, I was trying to motivate testing in the new code. Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. Comments from Reviewable |
Review status: all files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
nit: no need for the anonymous function, the capture would work the same with That is indeed the alternative, but I for one don't prefer it - then instead of worrying about whether I'm missing a My favorite option is still what I once sent to you and you've rejected with prejudice: a pkg/sql/pgwire/v3.go, line 351 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
To this I say - no again. The sane contract is that the callee always takes ownership, regardless of whether it returns an error or not. This is implemented naturally by callees that can afford to We could make Comments from Reviewable |
Review status: all files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. pkg/sql/pgwire/v3.go, line 351 at r1 (raw file):
meaning, I'd agree that contracts on errors returned in Go are more often ad-hoc. Comments from Reviewable |
let's not get caught up in an argument over dead code. My larger concern is how easy it is to get the memory accounting wrong. Our patterns for adding memory accounting are not robust. Review status: all files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file): Previously, andreimatei (Andrei Matei) wrote…
I think the function arguments (include the receiver) are captured when the defer is created. You only have to reset the rando variable in one place vs ensuring you call I don't recall previously rejecting a pkg/sql/pgwire/v3.go, line 351 at r1 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Well, Comments from Reviewable |
Review status: all files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. pkg/sql/pgwire/v3.go, line 340 at r1 (raw file):
FWIW seems to work without the anon func: https://play.golang.org/p/in2EvKo7zPH
Maybe, maybe not. Sometimes you can alternatively transfer ownership on different branches.
I'll reintroduce it with the following occasion in the 2018 proceedings and I'l quote you on this. Comments from Reviewable |
Want unique_ptr.
Release note: None