-
Notifications
You must be signed in to change notification settings - Fork 1
Missing graceful shutdown and environment variable validation #16
Copy link
Copy link
Open
Description
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_KEYdefault to empty string instead of failing fastREDIS_PORTparsed withparseIntwithout error handling (NaN on invalid input)- No format validation for private keys (0x prefix, valid hex, base58 encoding)
- No validation for contract addresses
Number()andBigInt()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
- 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
- Create a Zod schema for all environment variables
- Validate at startup, fail fast with clear error messages
- Validate format constraints (key formats, address formats, port ranges)
- Distinguish required vs optional with explicit defaults
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels