fix: preserve first stop shutdown ownership

This commit is contained in:
MiMoCode
2026-07-10 19:25:44 +08:00
parent 936e5dde65
commit 0520f75cdf
2 changed files with 45 additions and 1 deletions
+3 -1
View File
@@ -197,7 +197,9 @@ func (q *Queue) Stop(contexts ...context.Context) error {
}
q.mu.Lock()
shutdownOwner := false
if !q.stopped {
shutdownOwner = true
q.stopped = true
q.shutdownCtx = ctx
close(q.ch)
@@ -222,7 +224,7 @@ func (q *Queue) Stop(contexts ...context.Context) error {
case <-done:
return nil
case <-ctx.Done():
if workCancel != nil {
if shutdownOwner && workCancel != nil {
workCancel()
}
return ctx.Err()