fix(chromium): close file descriptor on protocol stream save error#40749
Merged
pavelfeldman merged 4 commits intomicrosoft:mainfrom May 9, 2026
Merged
Conversation
saveProtocolStream opens a write fd but does not close it when
client.send('IO.read') throws, leaking one file descriptor per
failed stream save. Wrap the read loop in try/finally to ensure
the fd is always closed.
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Move IO.close into the finally block alongside fd.close so the server-side stream handle is released even when IO.read throws. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
…olStream
- fd.close() can throw in the finally block and mask the original
IO.read error. Add .catch(() => {}) for consistency with IO.close.
- readProtocolStream has the same IO.close leak pattern. Wrap its
read loop in try/finally too.
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
pavelfeldman
reviewed
May 9, 2026
| } | ||
| } finally { | ||
| await fd.close().catch(() => {}); | ||
| await client.send('IO.close', { handle }).catch(() => {}); |
Member
There was a problem hiding this comment.
We are getting a nested throw here (IO.read throws, IO.close throws within), let's avoid that.
Keep only fd.close() in the finally block. IO.close is moved back to after the try/finally so it only runs on the success path, avoiding nested throws when both IO.read and IO.close fail. readProtocolStream reverted to original since it has no fd to protect; the try/finally was unnecessary. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Contributor
Author
|
Moved Also reverted |
pavelfeldman
approved these changes
May 9, 2026
Contributor
Test results for "MCP"2 failed 7042 passed, 1068 skipped Merge workflow run. |
Contributor
Test results for "tests 1"3 flaky41703 passed, 850 skipped Merge workflow run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
saveProtocolStreamopens a write fd but does not close it whenclient.send('IO.read')throws, leaking one file descriptor per failed stream savereadProtocolStreamhas the same pattern:IO.closeis not called ifIO.readthrowsFailure scenario: When Chromium's IO.read fails mid-stream (e.g., browser crash, session disconnect), the file descriptor opened at
fs.promises.open(path, 'w')is never closed. Each failed save leaks one OS file descriptor. Under sustained failures, this can exhaust the process file descriptor limit.Origin: The fd-based stream saving was introduced in #24414 (2023-07-26) by Pavel Feldman. The original code assumed IO.read would always succeed through EOF.