Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Add context done case
Browse files Browse the repository at this point in the history
If the context is done before all the tasks are read from the queue,
the remaining tasks on the queue will not be read and so the done
channel will not be closed causing the goroutine to wait forever.

This is solved by adding a context.Done() check so that when the
context is closed we can carry on with shutting down of the iteration.
  • Loading branch information
ankur22 committed Oct 18, 2024
1 parent aedd78e commit 67d6dc8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions browser/page_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,11 @@ func mapPageOn(vu moduleVU, p *common.Page) func(common.PageOnEventName, sobek.C
}
}

ctx := vu.Context()

// Run the the event handler in the task queue to
// ensure that the handler is executed on the event loop.
tq := vu.taskQueueRegistry.get(vu.Context(), p.TargetID())
tq := vu.taskQueueRegistry.get(ctx, p.TargetID())
eventHandler := func(event common.PageOnEvent) {
mapping := pageOnEvent.mapp(vu, event)

Expand All @@ -475,7 +477,10 @@ func mapPageOn(vu moduleVU, p *common.Page) func(common.PageOnEventName, sobek.C
})

if pageOnEvent.wait {
<-done
select {
case <-done:
case <-ctx.Done():
}
}
}

Expand Down

0 comments on commit 67d6dc8

Please sign in to comment.