Skip to content

Commit

Permalink
Merge pull request #2364 from lpsinger/sigint-sigterm
Browse files Browse the repository at this point in the history
Close Kafka connection on SIGINT or SIGTERM, not beforeExit
  • Loading branch information
dakota002 authored Jun 12, 2024
2 parents 6a1113d + cba9b5c commit c94e2d6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/lib/kafka.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ if (process.env.ARC_SANDBOX) {
async () => {
const producer = kafka.producer()
await producer.connect()
process.once('beforeExit', async () => {
console.log('Disconnecting from Kafka')
await producer.disconnect()
console.log('Disconnected from Kafka')
})
;['SIGINT', 'SIGTERM'].forEach((event) =>
process.once(event, async () => {
console.log('Disconnecting from Kafka')
await producer.disconnect()
console.log('Disconnected from Kafka')
})
)
return producer
},
{ promise: true }
Expand Down

0 comments on commit c94e2d6

Please sign in to comment.