agent-native icon indicating copy to clipboard operation
agent-native copied to clipboard

Built server: graceful stop closes the HTTP listener but background-job timers keep the Node process alive indefinitely

Open ai4U23 opened this issue 1 month ago • 1 comments

Environment

  • @agent-native/core 0.209.0 — studio-template app, Nitro build, output served with node .output/server/index.mjs (listhen server)
  • Node 22, macOS arm64 (local repro)
  • The server was launched without a hosted DATABASE_URL, so it resolved to local PGlite and ran in the guarded mode (DEPLOY_SETTINGS_REQUIRED, auth locked, 503s). That is an unsupported launch shape on purpose here: it makes every background-job tick print an error, which is what makes the timer leak measurable. The process-lifetime bug below is the report.

Steps to reproduce

  1. pnpm build a studio-template app.
  2. Run the built server without a hosted database: PORT=8097 node .output/server/index.mjs.
  3. Send SIGINT once (Ctrl+C). Console prints: Stopping server gracefully (5s)... Press Ctrl+C again to force close. then Server closed successfully.
  4. The HTTP listener is closed (port unbound, connections refused), but the process never exits.

Observed

Background interval jobs keep firing and failing forever after Server closed successfully:

  • [triggers] Event queue recovery scan failed: Error: ensureSchemaObject: could not probe required schema "table automation_trigger_event_queue"; refusing to issue DDL — ~3,730 occurrences
  • [integrations] Pending-tasks retry job error: ... "table integration_pending_tasks" — ~622
  • [integrations] A2A continuation retry job failed: ... "table integration_a2a_continuations" — ~622
  • [integrations] Remote push delivery failed { error: 'Error' } — ~622
  • one [unhandledRejection] for ensureSchemaObject ... "table integration_configs" immediately after the stop

Measured run: the process survived 10.5 hours past the graceful stop, still logging every retry interval (re-parented to PPID 1, TTY-less at that point, so interactive Ctrl+C was no longer possible). A later kill -INT — the second SIGINT the process ever received, i.e. the promised force-close — did not exit it within ~3 s; we escalated to SIGKILL rather than wait longer.

Expected

  • After the graceful close completes (or at worst on the second-SIGINT force-close), the background-job intervals (triggers event-queue recovery scan, integrations pending-tasks / A2A continuation retries, remote push delivery) are cleared or .unref()'d so the event loop drains and the process exits.
  • Server closed successfully should not print while these timers still own the event loop.

Suggested direction

Register the background-job timers with the runtime's shutdown path (e.g., Nitro close hooks) or .unref() them so they can never hold the process open; verify the force-close handler actually terminates.

Version notes

Observed on 0.209.0. The releases page shows 0.209.1 (2026-10-15) and 0.209.2 (2026-10-16) with no core changelog entries mentioning shutdown, graceful stop, or background timers, so this appears to still be current — but it is unverified on 0.209.1/0.209.2.

ai4U23 avatar Oct 17 '26 09:10 ai4U23

Happy to pick this up — will clear the background job intervals on graceful close and add a test that the process exits.

maxiaochaos avatar Oct 19 '26 02:10 maxiaochaos