fix(transport): dispose StdIOTransport and break event cycles on shutdown#3307
Merged
Conversation
…down Playwright.cs stores the transport event subscriptions as named locals so the connection.Close handler can unsubscribe them, drop OnMessage, and call transport.Dispose() — which previously was never invoked, so the Process, CancellationTokenSource, and reader Task accumulated per short-lived Playwright instance. StdIOTransport.cs converts its Process.Exited / ErrorDataReceived subscriptions to named methods so Dispose can unsubscribe them and release the Process eagerly. References microsoft#2962
pavelfeldman
approved these changes
May 1, 2026
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
StdIOTransport.Dispose()was never invoked from anywhere — onlyClose()was. Each call toPlaywright.CreateAsync()followed by disposal therefore leaked the underlyingProcess,CancellationTokenSource, and readerTask. The finalizer was a no-op (Dispose(false)returns immediately).Playwright.CreateAsync()now stores the fourtransport/connectionevent subscriptions as named locals; theconnection.Closehandler unsubscribes them, clearsconnection.OnMessage, callstransport.Close(reason), and finallytransport.Dispose(). This breaks theConnection<->Transportclosure cycle eagerly and releases the underlying resources.StdIOTransport'sProcess.Exited/ErrorDataReceivedlambdas are converted to named methods soDispose(true)can unsubscribe them and break theProcess<->Transportcycle.References #2962