Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Don't block the event loop on context end
Browse files Browse the repository at this point in the history
Previously setTimeout (and co) might block the event loop in cases where
timeout hasn't triggered but the context has been done.
  • Loading branch information
mstoykov committed Jan 11, 2024
1 parent 2207c55 commit 92cb8b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions timers/timers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,13 @@ func (e *Timers) closeTaskQueue() {
// so that we do not execute it twice
e.taskQueueCh = nil

// wait for this to happen so we don't need to hit the event loop again
// instead this just closes the queue
ch <- struct{}{}
<-ch
select {
case ch <- struct{}{}:
// wait for this to happen so we don't need to hit the event loop again
// instead this just closes the queue
<-ch
case <-e.vu.Context().Done(): // still shortcircuit if the context is done as we might block otherwise
}
}

func (e *Timers) setupTaskQueueCloserOnIterationEnd() {
Expand Down

0 comments on commit 92cb8b7

Please sign in to comment.