init2222
This commit is contained in:
@@ -3,6 +3,7 @@ import { env, initEnv } from './config/env';
|
||||
import { refreshAllKeys, startKeyRotation, stopKeyRotation } from './services/key-rotation.service';
|
||||
import { isCryptoReady, decryptMnemonic, encryptMnemonic } from './services/crypto.service';
|
||||
import { db } from './config/database';
|
||||
import { pingRedis, closeRedis } from './config/redis';
|
||||
import { logger } from './lib/logger';
|
||||
|
||||
// Global error handlers — иначе unhandled errors идут в stderr без sanitization (leak secrets)
|
||||
@@ -36,6 +37,15 @@ async function main() {
|
||||
// и любой /send или /sign будет тихо валиться с GCM auth error. Лучше упасть сразу.
|
||||
await runCryptoIntegritySelfTest();
|
||||
|
||||
// KeyDB / Redis ping — idempotency critical для money flow; fail-fast если недоступен.
|
||||
try {
|
||||
await pingRedis();
|
||||
logger.info('KeyDB/Redis self-test: PASSED');
|
||||
} catch (err: any) {
|
||||
logger.error(`KeyDB/Redis ping failed: ${err.message}. Refusing to start (idempotency unavailable).`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
startKeyRotation();
|
||||
|
||||
const server = app.listen(env.port, () => {
|
||||
@@ -45,6 +55,7 @@ async function main() {
|
||||
const shutdown = (signal: string) => {
|
||||
logger.info(`${signal} received, shutting down gracefully`);
|
||||
stopKeyRotation();
|
||||
void closeRedis();
|
||||
server.close(() => process.exit(0));
|
||||
// Force exit if shutdown takes too long
|
||||
setTimeout(() => process.exit(1), 10_000).unref();
|
||||
|
||||
Reference in New Issue
Block a user