Skip to content

Commit 3d0cf18

Browse files
committed
fix(signal): prevent cancel after context is done
Update the signal handling goroutine to avoid calling cancel if the context has already been completed. This prevents unnecessary cancellation and ensures proper cleanup when the context is already done.
1 parent 7f20c23 commit 3d0cf18

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

loggly.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,12 @@ func contextWithInterrupt(ctx context.Context) (context.Context, context.CancelF
212212
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
213213

214214
go func() {
215-
<-sigChan
216-
cancel()
215+
select {
216+
case <-ctx.Done():
217+
return
218+
case <-sigChan:
219+
cancel()
220+
}
217221
}()
218222
return ctx, cancel
219223
}

0 commit comments

Comments
 (0)