diff --git a/backend/services/mpc-service/src/application/services/event-consumer-starter.service.ts b/backend/services/mpc-service/src/application/services/event-consumer-starter.service.ts index bf2b6bf6..e7d4f092 100644 --- a/backend/services/mpc-service/src/application/services/event-consumer-starter.service.ts +++ b/backend/services/mpc-service/src/application/services/event-consumer-starter.service.ts @@ -16,11 +16,7 @@ export class EventConsumerStarterService implements OnApplicationBootstrap { async onApplicationBootstrap() { try { - // Don't await - consumer.run() never resolves (it runs continuously) - // Just fire and forget, let it run in the background - this.eventConsumer.startConsuming().catch((error) => { - this.logger.error('Kafka consumer error', error); - }); + await this.eventConsumer.startConsuming(); this.logger.log('MPC event consumers started successfully'); } catch (error) { this.logger.error('Failed to start MPC event consumers', error); diff --git a/backend/services/mpc-service/src/main.ts b/backend/services/mpc-service/src/main.ts index 5c5b43a2..2c8facde 100644 --- a/backend/services/mpc-service/src/main.ts +++ b/backend/services/mpc-service/src/main.ts @@ -18,6 +18,10 @@ async function bootstrap() { logger: ['error', 'warn', 'log', 'debug', 'verbose'], }); + // Enable graceful shutdown hooks (calls onModuleDestroy on SIGTERM/SIGINT) + // This ensures Kafka consumer disconnects properly, allowing fast rebalance on restart + app.enableShutdownHooks(); + // Get config service const configService = app.get(ConfigService); const port = parseInt(process.env.APP_PORT || '3006', 10);