Skip to content

Missing graceful shutdown and environment variable validation #16

@adambalogh

Description

@adambalogh

Description

Two related infrastructure issues that affect production reliability:

1. No Graceful Shutdown

The server has no SIGTERM/SIGINT signal handlers. When the process is stopped (e.g., during deployment, scaling, or container restart):

  • In-flight requests are dropped without response
  • Redis connections are not closed cleanly
  • Worker processes are not drained
  • Active blockchain transactions may be left in an unknown state

2. Weak Environment Variable Validation

18+ process.env accesses without validation. Critical issues:

  • EVM_PRIVATE_KEY / SVM_PRIVATE_KEY default to empty string instead of failing fast
  • REDIS_PORT parsed with parseInt without error handling (NaN on invalid input)
  • No format validation for private keys (0x prefix, valid hex, base58 encoding)
  • No validation for contract addresses
  • Number() and BigInt() conversions on env vars without guards

Impact

  • Deployments cause request failures and potential data loss
  • Misconfigured environments silently misbehave instead of failing at startup
  • Invalid private keys cause cryptic runtime errors instead of clear startup failures

Fix

Graceful Shutdown

  1. Add SIGTERM/SIGINT handlers that:
    • Stop accepting new requests
    • Wait for in-flight requests to complete (with timeout)
    • Drain worker queues
    • Close Redis connections
    • Exit cleanly

Environment Validation

  1. Create a Zod schema for all environment variables
  2. Validate at startup, fail fast with clear error messages
  3. Validate format constraints (key formats, address formats, port ranges)
  4. Distinguish required vs optional with explicit defaults

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