Skip to content

100% CPU infinite loop when browser context becomes unresponsive #16

@neoncapy

Description

@neoncapy

Summary

The NotebookLM MCP server can get stuck in an infinite loop consuming 100% CPU for days when the underlying browser context becomes unresponsive or enters a zombie state.

Observed Behavior

  • Process running at 100% CPU continuously for 80+ hours (4834 minutes CPU time)
    • Only resolved by kill -9 (regular kill was ineffective)
      • Process command: node /Users/.../.npm/_npx/.../node_modules/.bin/notebooklm-mcp

Root Cause Analysis

After examining the source code, the issue appears to be in page-utils.js in the waitForLatestAnswer() function:

while (Date.now() < deadline) {  // 2 minute timeout
    pollCount++;
    // ... polling logic ...
    await page.waitForTimeout(pollIntervalMs);  // Should wait 1 second
}

What happens:

  1. The Chromium browser (managed by Patchright) becomes unresponsive or enters a bad state
    1. page.waitForTimeout(1000) returns immediately instead of waiting 1 second (because the browser connection is broken)
    1. The while loop becomes a tight spin loop with no actual waiting
    1. The 2-minute deadline never triggers because Date.now() is called, but the CPU is saturated
      Why detection fails:
      The recovery logic checks for specific error messages:
if (/has been closed|Target .* closed|Browser has been closed|Context .* closed/i.test(msg))

But a zombie browser (unresponsive but not cleanly closed) doesn't trigger these patterns.

Suggested Fixes

  1. Add maximum poll count limit:
  2. const MAX_POLLS = 7200; // 2 hours max at 1s intervals
  3. while (Date.now() < deadline && pollCount < MAX_POLLS) {
  4. Add health check for the page:
  5. try {
  6. await page.evaluate(() => true);  // Simple aliveness check
    
  7. } catch {
  8. throw new Error("Browser page unresponsive");
    
  9. }
  10. Exponential backoff on repeated empty polls

Environment

  • Node.js: v20+
    • notebooklm-mcp version: 1.2.1
      • OS: macOS (Darwin)
        • Patchright/Playwright version: 1.48.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions