{"record":{"id":"ec42647d3c85b41f","repo":"d2lang/d2","slug":"failed-to-stop-playwright-w","errorCode":null,"errorMessage":"failed to stop Playwright: %w","messagePattern":"failed to stop Playwright: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/png/png.go","lineNumber":44,"sourceCode":"type Playwright struct {\n\tPW      *playwright.Playwright\n\tBrowser playwright.Browser\n\tPage    playwright.Page\n}\n\nfunc (pw *Playwright) RestartBrowser() (Playwright, error) {\n\tif err := pw.Browser.Close(); err != nil {\n\t\treturn Playwright{}, fmt.Errorf(\"failed to close Playwright browser: %w\", err)\n\t}\n\treturn startPlaywright(pw.PW)\n}\n\nfunc (pw *Playwright) Cleanup() error {\n\tif err := pw.Browser.Close(); err != nil {\n\t\treturn fmt.Errorf(\"failed to close Playwright browser: %w\", err)\n\t}\n\tif err := pw.PW.Stop(); err != nil {\n\t\treturn fmt.Errorf(\"failed to stop Playwright: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc startPlaywright(pw *playwright.Playwright) (Playwright, error) {\n\t// Optimizations for a very tightly scoped Playwright instance\n\tbrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{\n\t\tArgs: []string{\n\t\t\t\"--no-sandbox\",                             // Removes security overhead\n\t\t\t\"--disable-dev-shm-usage\",                  // Prevents /dev/shm issues\n\t\t\t\"--disable-background-timer-throttling\",    // Prevents CPU throttling\n\t\t\t\"--disable-backgrounding-occluded-windows\", // Keeps rendering active\n\t\t\t\"--disable-features=TranslateUI\",           // Reduces feature overhead\n\t\t\t\"--disable-ipc-flooding-protection\",        // Removes IPC limits\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn Playwright{}, fmt.Errorf(\"failed to launch Chromium: %w\", err)","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/lib/png/png.go#L26-L62","documentation":"Cleanup, after successfully closing the browser, stops the Playwright driver process with pw.PW.Stop(). If that fails it returns this wrapped error. The driver (node process managing browsers) could not be terminated, potentially leaving orphaned node/Chromium processes.","triggerScenarios":"pw.PW.Stop() returns an error during Cleanup — driver process already exited (e.g. after a browser crash), broken pipe to the driver, or Stop racing a concurrent Cleanup.","commonSituations":"Shutdown after Chromium crashed taking the driver with it; SIGTERM handling that calls Cleanup while the driver is mid-operation; test suites leaking drivers when this path fails.","solutions":["Check for orphaned node/chromium processes after the error and kill them manually if needed","Make Cleanup idempotent and single-run (sync.Once) to avoid racing Stop against itself","Log and continue: Stop failure at process exit is rarely fatal, so don't mask the original operation's result with it","Upgrade playwright-go to the latest version — driver lifecycle bugs are fixed regularly"],"exampleFix":"// before\nif err := pw.PW.Stop(); err != nil {\n\treturn fmt.Errorf(\"failed to stop Playwright: %w\", err)\n}\n// after\nif err := pw.PW.Stop(); err != nil {\n\tlog.Printf(\"playwright stop failed (driver may have already exited): %v\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := pw.Cleanup(); err != nil {\n\tif strings.Contains(err.Error(), \"failed to stop Playwright\") {\n\t\t// check for orphaned driver processes; don't mask the original error\n\t}\n}","preventionTips":["Make Cleanup idempotent with sync.Once","Upgrade playwright-go regularly for driver lifecycle fixes","After shutdown errors, sweep orphaned node/chromium processes","Log Stop failures at warning level instead of failing shutdown"],"tags":["playwright","driver","cleanup","process","go"],"backgroundTag":"playwright-driver-stop-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}