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

client: fix hctx leakage in addrConn.createTransport #5337

Merged
merged 3 commits into from May 23, 2022

Conversation

carzil
Copy link
Contributor

@carzil carzil commented May 4, 2022

Fixes #5336

RELEASE NOTES:

  • client: fix a context leaked if a connection to an address is lost before it is fully established

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 4, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: carzil / name: Alexander Andreev (9e1c3cb)

@dfawley
Copy link
Member

dfawley commented May 10, 2022

It looks like, even with this change, we won't call hcancel in situations where health checking wasn't started. It seems like we should also move the hcancel in the onClose to happen unconditionally above the if !hcStarted || ctx.Err() != nil, or a similar leak could occur.

@dfawley
Copy link
Member

dfawley commented May 10, 2022

It seems like we should also move the hcancel in the onClose to happen unconditionally above the if !hcStarted || ctx.Err() != nil, or a similar leak could occur.

Actually this doesn't work, since the following if will always trigger....

@carzil
Copy link
Contributor Author

carzil commented May 11, 2022

It looks like, even with this change, we won't call hcancel in situations where health checking wasn't started. It seems like we should also move the hcancel in the onClose to happen unconditionally above the if !hcStarted || ctx.Err() != nil, or a similar leak could occur.

Could you please given an example of such a flow?

I think that moving hcancel to the start of onClose is a good idea, because context cancelation is idempotent.

@dfawley
Copy link
Member

dfawley commented May 12, 2022

Could you please given an example of such a flow?

If the server's preface is not received before the connection is lost, or if the connection is lost immediately after receiving the preface and a race causes onClose to be called before the prefaceReceived case of the select wakes up. (Once we move the logic that waits for the preface into transport.NewClientTransport, this will no longer be a concern. It's done this way for historical reasons but can now be changed whenever we have the time to do the work.)

Tests seem to be failing now, probably because of this:

Actually this doesn't work, since the following if will always trigger....

I think if you defer hcancel() instead it will work, so the following if won't always be entered.

@dfawley dfawley added this to the 1.47 Release milestone May 16, 2022
@dfawley dfawley requested a review from menghanl May 16, 2022 16:28
@menghanl menghanl assigned dfawley and unassigned menghanl May 20, 2022
@dfawley dfawley changed the title fix hctx leakage in addrConn.createTransport client: fix hctx leakage in addrConn.createTransport May 23, 2022
@dfawley dfawley merged commit 081c688 into grpc:master May 23, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2022
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.

Internal context leak in client connection
3 participants