Skip to content

Commit 942c0cf

Browse files
craig[bot]herkolategan
andcommitted
Merge #153277
153277: roachtest: indefinite block on task events r=srosenberg a=herkolategan Previously, we could end up with dangling goroutines for tasks if some tasks were trying to send events, but the consumer has already stopped consuming events. This would cause an indefinite block in the task goroutine when trying to send the event. This change adds a `select` when trying to send the events, but if the context has been cancelled, it will break out. There's a small chance that the event could end up being sent even if the context has been canceled, but on the consumer side we also check for a canceled context. Epic: None Release note: None Co-authored-by: Herko Lategan <[email protected]>
2 parents e860c36 + 15af1dc commit 942c0cf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/cmd/roachtest/roachtestutil/task/manager.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,18 @@ func (t *group) GoWithCancel(fn Func, opts ...Option) context.CancelFunc {
229229
return nil
230230
}
231231
if !opt.DisableReporting {
232-
t.manager.events <- event
232+
// There's a slight chance that the context is canceled between the check
233+
// above and this select. In which case Go might probabilistically select
234+
// sending the event. This should not cause issues as the consumer of the
235+
// events should also check if the parent context is canceled. But we
236+
// require the select here to avoid blocking if the parent context is
237+
// canceled, and the consumer is no longer consuming events.
238+
select {
239+
case t.manager.events <- event:
240+
case <-t.manager.ctx.Done():
241+
// do not send the event if the parent context is canceled
242+
return nil
243+
}
233244
}
234245
return err
235246
})

0 commit comments

Comments
 (0)