Skip to content

Commit 547ec1f

Browse files
zeripath6543
authored andcommitted
Queue manager FlushAll can loop rapidly - add delay (go-gitea#15733)
* Queue manager FlushAll can loop rapidly - add delay Add delay within FlushAll to prevent rapid loop when workers are busy Signed-off-by: Andrew Thornton <art27@cantab.net> * as per lunny Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
1 parent 7fa43d0 commit 547ec1f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

modules/queue/manager.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,20 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
198198
wg.Done()
199199
}(mq)
200200
} else {
201-
log.Debug("Queue: %s is non-empty but is not flushable - adding 100 millisecond wait", mq.Name)
202-
go func() {
203-
<-time.After(100 * time.Millisecond)
204-
wg.Done()
205-
}()
201+
log.Debug("Queue: %s is non-empty but is not flushable", mq.Name)
202+
wg.Done()
206203
}
207-
208204
}
209205
if allEmpty {
206+
log.Debug("All queues are empty")
210207
break
211208
}
209+
// Ensure there are always at least 100ms between loops but not more if we've actually been doing some flushign
210+
// but don't delay cancellation here.
211+
select {
212+
case <-ctx.Done():
213+
case <-time.After(100 * time.Millisecond):
214+
}
212215
wg.Wait()
213216
}
214217
return nil

0 commit comments

Comments
 (0)