Skip to content

fix: close Node listeners during graceful shutdown - #1743

Merged
kang-heewon merged 1 commit into
trunkfrom
fix/1684-node-graceful-shutdown
Aug 4, 2026
Merged

fix: close Node listeners during graceful shutdown#1743
kang-heewon merged 1 commit into
trunkfrom
fix/1684-node-graceful-shutdown

Conversation

@kang-heewon

Copy link
Copy Markdown
Member

Outcome

Signal-driven shutdown failures are now observed exactly once, logged safely even when the configured logger fails, and reflected through a nonzero process exit code instead of becoming unhandled rejections.

Node servers created by CrocoApp.listen() are bound to configured graceful-shutdown middleware. Shutdown rejects new work, drains active requests, closes each listener, drains the event bus, and then runs the configured hook. Timeout fallback force-closes retained HTTP connections, while repeated signals and late listeners remain idempotent without interrupting an existing drain.

Fixes #1684

Verification

  • pnpm --filter @croco/framework-context test — 189 passed.
  • pnpm --filter @croco/transports-http test — 400 passed.
  • Affected package typecheck, lint, and build checks passed.
  • pnpm public-api:check and pnpm problem-registry:check passed.
  • pnpm check — 24/25 passed, 1 not applicable.
  • Pre-push workspace gates — 234/234 test tasks and 233/233 typecheck tasks passed.

Review gates

  • Correctness and regression — PASS. Signal timeout and logger-failure tests prove observed failure and idempotency; real Node socket tests cover SIGTERM, keep-alive drain, rejection of new work, listener closure before hooks, timeout force-close, and late-listener isolation.
  • API, security, compatibility, and release — PASS. Binding remains internal to the Node listen() path, Lambda/fetch semantics and public types are unchanged, failure logs retain structured errors, and patch changesets cover both affected packages.
  • Maintainability and minimality — PASS. The implementation reuses existing graceful controller state and middleware identity without adding a parallel public lifecycle API.
  • Independent adversarial review — PASS after fixes. Late-listener cross-interruption and no-logger silent failure were identified, fixed, covered by regressions, and re-reviewed clean.

Validation gap

pnpm docs:api:check still reports unrelated generated API drift already carried by #1727 (desktop grants, GraphQL policy decorators, and billing conformance types). This PR does not add public API documentation drift.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kang-heewon, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cdd70fee-0008-4216-bb0d-5993618ee281

📥 Commits

Reviewing files that changed from the base of the PR and between 31636bb and 4f788d6.

📒 Files selected for processing (9)
  • .changeset/observable-node-shutdown.md
  • packages/framework-context/README.md
  • packages/framework-context/src/libs/ShutdownManager.ts
  • packages/framework-context/src/tests/ShutdownManager.spec.ts
  • packages/transports-http/README.md
  • packages/transports-http/src/libs/CrocoApp.ts
  • packages/transports-http/src/libs/middleware/GracefulShutdownMiddleware.ts
  • packages/transports-http/src/tests/GracefulShutdownMiddleware.spec.ts
  • packages/transports-http/src/tests/NodeAdapterSmoke.spec.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

📊 Benchmark Results

✅ All benchmarks passed

Benchmark p75 Threshold Baseline vs Baseline Status Notes
CrocoApp constructor 43.1μs 30.0ms 8.2μs +427.5% -
CrocoApp lambdaHandler (10 controllers) 1.9ms 50.0ms 258.4μs +648.5% -
Lambda cold-start simulation 1.8ms 80.0ms 418.1μs +335.7% -
Lambda cold-start with headers 1.5ms 80.0ms 369.7μs +313.2% -
Lambda cold-start with binary body 1.5ms 80.0ms 339.1μs +341.7% -
Lambda cold-start with query params 1.5ms 80.0ms 301.3μs +401.5% -
Lambda cold-start with authorizer context 1.5ms 80.0ms 299.8μs +390.2% -
Lambda cold-start realistic scenario 1.5ms 80.0ms 299.2μs +388.7% -
EventBusConfig.start (10 handlers) 1.6μs 10.0ms 1.4μs +13.3% -
EventPublisher.publishNow single event 1.9μs 2.0ms 1.7μs +11.3% -
DefaultHandlerResolver.resolve × 10 0.1μs 5.0ms 0.1μs +0.0% -
Container.get singleton (cold) 87.5μs 5.0ms 70.3μs +24.5% -
Container.register × 50 components 3.4ms 10.0ms 3.2ms +5.3% -
Container.validate (50 components) 3.9ms 20.0ms 3.4ms +14.4% -
Container.get singleton (warm) 1.7μs 500.0μs 1.6μs +3.1% -
TelemetryRuntime.init (lambda preset) 2.3μs 200.0ms 1.1ms -99.8% -
lambdaPreset config creation 1.5μs 2.0ms 1.4μs +2.9% -

Updated: 2026-08-04T09:32:32.542Z · Commit: 283efc5

@kang-heewon
kang-heewon merged commit e3bb85e into trunk Aug 4, 2026
11 checks passed
@kang-heewon
kang-heewon deleted the fix/1684-node-graceful-shutdown branch August 4, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[runtime] Make SIGTERM/SIGINT close the Node listener and handle shutdown failure

1 participant