Skip to content

Comments

Disconnect kafka consumers on sigterm#441

Merged
nikosd23 merged 1 commit intomasterfrom
kafka-sigterm
Feb 20, 2026
Merged

Disconnect kafka consumers on sigterm#441
nikosd23 merged 1 commit intomasterfrom
kafka-sigterm

Conversation

@nikossaravanos-workable
Copy link
Contributor

No description provided.

@nikosd23
Copy link
Contributor

Code review

Found 1 issue:

  1. handleSigterm disconnects consumers fire-and-forget with no mechanism to hold the process alive until disconnects complete. Since handleSigterm is synchronous and returns immediately after starting the promises, Node.js can (and typically will) proceed to exit before any consumer.disconnect() call resolves — defeating the entire purpose of graceful shutdown. The existing disconnect() method uses await this.producer.disconnect() for exactly this reason.

private handleSigterm() {
logger.info('Received SIGTERM. Cancelling kafka consumers..');
for (const [groupId, consumer] of this.consumers) {
consumer.disconnect()
.then(() => {
logger.debug(`Consumer for kafka group ${groupId} disconnected.`);
}).catch(e => {
logger.error(`Consumer for kafka group ${groupId} failed to disconnect`, e);
});
}
}

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@nikossaravanos-workable
Copy link
Contributor Author

The SIGTERM will not kill the process, the SIGKILL will after 30s

Code review

Found 1 issue:

  1. handleSigterm disconnects consumers fire-and-forget with no mechanism to hold the process alive until disconnects complete. Since handleSigterm is synchronous and returns immediately after starting the promises, Node.js can (and typically will) proceed to exit before any consumer.disconnect() call resolves — defeating the entire purpose of graceful shutdown. The existing disconnect() method uses await this.producer.disconnect() for exactly this reason.

private handleSigterm() {
logger.info('Received SIGTERM. Cancelling kafka consumers..');
for (const [groupId, consumer] of this.consumers) {
consumer.disconnect()
.then(() => {
logger.debug(`Consumer for kafka group ${groupId} disconnected.`);
}).catch(e => {
logger.error(`Consumer for kafka group ${groupId} failed to disconnect`, e);
});
}
}

🤖 Generated with Claude Code

  • If this code review was useful, please react with 👍. Otherwise, react with 👎.

@nikosd23 nikosd23 merged commit 71b3617 into master Feb 20, 2026
24 checks passed
@nikosd23 nikosd23 deleted the kafka-sigterm branch February 20, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants