Skip to content

Commit

Permalink
Add unsubscribe in handleExitEvent
Browse files Browse the repository at this point in the history
We've found that when we perform a e2e test in k6 that the goroutines
handling the handleIterEvents do not get cleared away. This is due to
us not unsubscribing when the test exits.
  • Loading branch information
ankur22 committed Aug 2, 2023
1 parent b762a08 commit 595aeb7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions browser/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ func newBrowserRegistry(vu k6modules.VU, remote *remoteRegistry, pids *pidRegist
exitSubID, exitCh := vu.Events().Global.Subscribe(
k6event.Exit,
)
go r.handleExitEvent(exitCh)

iterSubID, eventsCh := vu.Events().Local.Subscribe(
k6event.IterStart,
k6event.IterEnd,
Expand All @@ -223,6 +221,8 @@ func newBrowserRegistry(vu k6modules.VU, remote *remoteRegistry, pids *pidRegist
vu.Events().Local.Unsubscribe(iterSubID)
vu.Events().Global.Unsubscribe(exitSubID)
}

go r.handleExitEvent(exitCh, unsubscribe)
go r.handleIterEvents(eventsCh, unsubscribe)

return r
Expand Down Expand Up @@ -282,7 +282,9 @@ func (r *browserRegistry) handleIterEvents(eventsCh <-chan *k6event.Event, unsub
}
}

func (r *browserRegistry) handleExitEvent(exitCh <-chan *k6event.Event) {
func (r *browserRegistry) handleExitEvent(exitCh <-chan *k6event.Event, unsubscribeFn func()) {
defer unsubscribeFn()

e, ok := <-exitCh
if !ok {
return
Expand Down

0 comments on commit 595aeb7

Please sign in to comment.