Skip to content

fix(transport): dispose StdIOTransport and break event cycles on shutdown#3307

Merged
dgozman merged 1 commit into
microsoft:mainfrom
dgozman:fix-2962
May 1, 2026
Merged

fix(transport): dispose StdIOTransport and break event cycles on shutdown#3307
dgozman merged 1 commit into
microsoft:mainfrom
dgozman:fix-2962

Conversation

@dgozman
Copy link
Copy Markdown
Collaborator

@dgozman dgozman commented May 1, 2026

Summary

  • StdIOTransport.Dispose() was never invoked from anywhere — only Close() was. Each call to Playwright.CreateAsync() followed by disposal therefore leaked the underlying Process, CancellationTokenSource, and reader Task. The finalizer was a no-op (Dispose(false) returns immediately).
  • Playwright.CreateAsync() now stores the four transport/connection event subscriptions as named locals; the connection.Close handler unsubscribes them, clears connection.OnMessage, calls transport.Close(reason), and finally transport.Dispose(). This breaks the Connection<->Transport closure cycle eagerly and releases the underlying resources.
  • StdIOTransport's Process.Exited / ErrorDataReceived lambdas are converted to named methods so Dispose(true) can unsubscribe them and break the Process<->Transport cycle.

References #2962

…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
@dgozman dgozman merged commit 22b9bc7 into microsoft:main May 1, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants