Skip to content

Add unhandledRejection/uncaughtException handlers to src/index.ts that trigger graceful shutdown #176

Description

@Jagadeeshftw

📌 Description

If src/index.ts doesn't register process.on('unhandledRejection', ...) / process.on('uncaughtException', ...), an unhandled async error can crash the process abruptly without draining connections or logging enough context to debug, instead of going through the existing graceful path in src/shutdown.ts.

🧩 Requirements and context

  • Register both handlers in src/index.ts, logging the error with full context (stack, request id if available).
  • Route the crash through the existing shutdown sequence in src/shutdown.ts rather than calling process.exit directly.
  • Ensure the force-exit timeout guard still applies so a hung shutdown doesn't block forever.

🛠️ Suggested execution

  1. Add the two process.on handlers in src/index.ts, invoking the shutdown function from src/shutdown.ts.
  2. Add a test that simulates an unhandled rejection and asserts shutdown is invoked.

✅ Acceptance criteria

  • An unhandled rejection/exception is logged with context and triggers graceful shutdown, not an abrupt crash.
  • The existing force-exit timeout still guards against a hung shutdown.

🔒 Security notes

Ensure the logged error context doesn't include secrets (e.g. full request bodies with credentials).

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions