Skip to content

hackbrowser: gracefully stop active crawls on server shutdown (SIGTERM/SIGINT) #113

Description

@badchars

Summary

Follow-up to the crawl-lifetime fix (crawl now runs in the background to its own maxPages/empty queue instead of dying at turn-end). With that change, a background crawl can be alive when the server process exits. There is no shutdown hook that gracefully stops active hackbrowser runs, so on SIGTERM/SIGINT the worker subprocess (and its Chromium) may be left to die ungracefully — risking orphaned/zombie Chromium processes and a browser that never closed cleanly.

Current state

  • Workers are spawned via Bun.spawn (not detached). activeRuns holds one handle per session.
  • stopHackbrowser(sessionID) sends {type:"abort"} so the worker finishes the current page, closes the browser, and exits — the graceful path.
  • No process.on("SIGTERM"|"SIGINT") / shutdown handler iterates activeRuns to stop them.

Proposed

Add a shutdown hook that, on SIGTERM/SIGINT (and normal server exit), calls stopHackbrowser for every entry in activeRuns and waits briefly for graceful browser close before the process exits. Backstop: hard-kill any worker still alive after a short grace period (the launcher already schedules a proc.kill() after 10s on its own cleanup path).

Notes

  • Genuine per-session teardown paths are already covered: Esc (/abort) and session delete (Session.remove). This issue is only the process-level exit path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions