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

Commit 595aeb7

Browse files
committed
Add unsubscribe in handleExitEvent
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.
1 parent b762a08 commit 595aeb7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

browser/registry.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ func newBrowserRegistry(vu k6modules.VU, remote *remoteRegistry, pids *pidRegist
213213
exitSubID, exitCh := vu.Events().Global.Subscribe(
214214
k6event.Exit,
215215
)
216-
go r.handleExitEvent(exitCh)
217-
218216
iterSubID, eventsCh := vu.Events().Local.Subscribe(
219217
k6event.IterStart,
220218
k6event.IterEnd,
@@ -223,6 +221,8 @@ func newBrowserRegistry(vu k6modules.VU, remote *remoteRegistry, pids *pidRegist
223221
vu.Events().Local.Unsubscribe(iterSubID)
224222
vu.Events().Global.Unsubscribe(exitSubID)
225223
}
224+
225+
go r.handleExitEvent(exitCh, unsubscribe)
226226
go r.handleIterEvents(eventsCh, unsubscribe)
227227

228228
return r
@@ -282,7 +282,9 @@ func (r *browserRegistry) handleIterEvents(eventsCh <-chan *k6event.Event, unsub
282282
}
283283
}
284284

285-
func (r *browserRegistry) handleExitEvent(exitCh <-chan *k6event.Event) {
285+
func (r *browserRegistry) handleExitEvent(exitCh <-chan *k6event.Event, unsubscribeFn func()) {
286+
defer unsubscribeFn()
287+
286288
e, ok := <-exitCh
287289
if !ok {
288290
return

0 commit comments

Comments
 (0)