{"record":{"id":"3207bb399783749f","repo":"santifer/career-ops","slug":"context-cleanup-failed-err-message","errorCode":null,"errorMessage":"⚠️  Context cleanup failed: ${err.message}","messagePattern":"⚠️  Context cleanup failed: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"generate-pdf.mjs","lineNumber":1806,"sourceCode":"      // The PDF itself succeeded — never fail the run over manifest bookkeeping.\n      console.error(`⚠️  Manifest update failed: ${err.message}`);\n    }\n\n    return { outputPath, pageCount, size: pdfBuffer.length };\n  } finally {\n    // Close the page so a batch does not accumulate pages into the shared\n    // browser (leak → OOM). Optional-chained: the single path's browser.close()\n    // already reclaims the page, and minimal test doubles may omit close().\n    if (page && typeof page.close === 'function') {\n      await page.close().catch((err) => {\n        console.warn(`⚠️  Page cleanup failed: ${err.message}`);\n      });\n    }\n    // Close the per-document context too, so the JS-disabled context created\n    // above does not accumulate in the shared browser across a batch (#2384).\n    if (context && typeof context.close === 'function') {\n      await context.close().catch((err) => {\n        console.warn(`⚠️  Context cleanup failed: ${err.message}`);\n      });\n    }\n    // Clean up temp file\n    await unlink(tmpHtmlPath).catch((err) => {\n      if (err?.code !== 'ENOENT') {\n        console.warn(`⚠️  Temporary HTML cleanup failed: ${err.message}`);\n      }\n    });\n  }\n}\n\n/**\n * Render many already-normalized HTML documents through ONE shared Chromium.\n *\n * Maintainer conditions (#2384): the browser is launched once via the same\n * opts.launchBrowser seam the single path uses, and closed in a finally at the\n * batch boundary — it never outlives the batch and is torn down even if a\n * document throws. Each entry renders on its own page (renderInPage), and a","sourceCodeStart":1788,"sourceCodeEnd":1824,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/generate-pdf.mjs#L1788-L1824","documentation":"Warning emitted when closing the per-document BrowserContext rejects. Each rendered document gets its own (JS-disabled) context so contexts do not accumulate in the shared browser across a batch (#2384); a failed close means the context may linger in memory until the browser itself closes.","triggerScenarios":"context.close() rejects in the finally after render — the context was already detached because the browser died, the page inside it crashed taking the context down, or the connection to the browser process was severed mid-batch.","commonSituations":"Shared-browser batch rendering where an earlier document crashed Chromium; context closed concurrently elsewhere; Playwright version mismatch between driver and browser build.","solutions":["Benign if the browser is closed right after in the same finally block — contexts die with it","Reduce batch size / add periodic browser restarts to avoid mid-batch crashes","Run npx playwright install to align driver and browser versions","If contexts accumulate without warnings being the cause, check for code paths that skip the finally"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"if (context && typeof context.close === 'function') { /* safe to close */ }","tryCatchPattern":"await context.close().catch((err) => {\n  if (!/Target closed|Connection closed/i.test(err.message)) {\n    console.warn(`Context cleanup failed: ${err.message}`);\n  }\n});","preventionTips":["Close the per-document context in finally (as this code does) to prevent context accumulation (#2384)","Avoid closing the same context from two code paths","Keep driver and browser versions aligned","Split very large batches so a late crash does not strand many contexts"],"tags":["playwright","browser-context","cleanup","memory-leak"],"backgroundTag":"browser-cleanup-failed","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}