Skip to content

Fix memory leak in HTTP request security handshake cancellation#28971

Merged
apolcyn merged 3 commits intogrpc:masterfrom
apolcyn:fix_leak
Mar 1, 2022
Merged

Fix memory leak in HTTP request security handshake cancellation#28971
apolcyn merged 3 commits intogrpc:masterfrom
apolcyn:fix_leak

Conversation

@apolcyn
Copy link
Copy Markdown
Contributor

@apolcyn apolcyn commented Feb 24, 2022

The caller of the Handshake API, owns output arguments if the handshake completes successfully. So there's currently a potential race where a handshake completion can be scheduled successfully but the HTTP request is cancelled before the completion runs.

b/220992477

@apolcyn apolcyn added lang/core release notes: no Indicates if PR should not be in release notes release notes: yes Indicates if PR needs to be in release notes and removed release notes: no Indicates if PR should not be in release notes labels Feb 24, 2022
@ctiller
Copy link
Copy Markdown
Member

ctiller commented Feb 24, 2022

Is there any way we can add a test for this?

@apolcyn
Copy link
Copy Markdown
Contributor Author

apolcyn commented Feb 24, 2022

Is there any way we can add a test for this?

Outside of finding the right concurrency settings in the test to tickle the race more frequently, we could probably coordinate the race with a mock channel creds. I haven't gotten to that yet but I'll look into that.

@markdroth
Copy link
Copy Markdown
Member

You probably don't need a mock channel creds, just a mock handshaker. You can register a handshaker directly without going through channel creds (example).

@apolcyn
Copy link
Copy Markdown
Contributor Author

apolcyn commented Mar 1, 2022

I put together the mock handshake approach, but I realized that the handshake manager also has shutdown logic which needed to be overridden too, in order to trigger the race.

I went with a different approach which I think winds up being simpler. PTAL

Copy link
Copy Markdown
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

Looks great!

@apolcyn
Copy link
Copy Markdown
Contributor Author

apolcyn commented Mar 1, 2022

failures are pre-existing

@apolcyn apolcyn merged commit 20521fb into grpc:master Mar 1, 2022
@copybara-service copybara-service Bot added the imported Specifies if the PR has been imported to the internal repository label Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bloat/none imported Specifies if the PR has been imported to the internal repository lang/core perf-change/none release notes: yes Indicates if PR needs to be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants