[Bug]: Playwright.Dispose() can hang forever while the driver is still sending messages

Chiusa
#3,419 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #3380 di @PrzemyslawKlys — chiusa senza merge
  • #3421 di @dgozman — integrata

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, node.js
Ambito
backend, devtools

Direzione di ricerca

Start by reading StdIOTransport.Close, the TransportClosed listener, and the _readerCancellationSource.Cancel() call mentioned in the report. Trace how closing stdin, reading stdout, and waiting for the driver interact when the stdout pipe fills on Windows; reproduce with the supplied busy-page example or the blocking stdout setup described. Done means Dispose() returns after the driver exits without deadlocking, and transport closure does not throw ObjectDisposedException.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version

1.64.0, also current main

Steps to reproduce

Dispose Playwright while the driver is still sending protocol messages, for example events from a busy page:

var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
page.Console += (_, _) => { };
await page.EvaluateAsync("() => { setInterval(() => { for (let i = 0; i < 200; i++) console.log('x'.repeat(20000)); }, 0); }");
await Task.Delay(500);
playwright.Dispose();

The same happens when Dispose() is called from inside an event handler.

Expected behavior

Dispose() returns once the driver has exited.

Actual behavior

Dispose() never returns. The thread is blocked in StdIOTransport.Close → Process.WaitForExit.

StdIOTransport.Close stops reading the driver's stdout, closes its stdin and waits for the process to exit. The driver exits when its event loop sees stdin closed. On Windows, Node.js writes to a piped stdout synchronously, so a driver that is in the middle of writing blocks as soon as the pipe is full. It never gets to the stdin handler, nor to its own 30 second exit timer, and each side waits for the other.

On Linux and macOS the driver writes to the pipe asynchronously, so it sees stdin closed and exits; there is no hang there.

Additional context

Reported with a fix in #3380, where a downstream testhost dump shows the thread blocked in StdIOTransport.Close / Process.WaitForExit.

I have not run the snippet on Windows. On macOS it hangs every time when the driver's stdout is switched to blocking mode with process.stdout._handle.setBlocking(true), which is what Node.js does for a pipe on Windows, and it does not hang without that.

Since #3307 there is a related defect in the same method: TransportClosed is raised first, its listener disposes the transport, and the following _readerCancellationSource.Cancel() throws ObjectDisposedException when the transport closes on its own, for example after the driver exits.

Lingua principale
C#
Stelle
3k
Fork
307
Merge medio
1g 14h
PR unite (30g)
32

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/playwright-dotnet

Tutte le issue di microsoft/playwright-dotnet

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.