From 45694efd96b98346552c9895e353f52e30fa4a6d Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 3 Aug 2023 14:07:23 +0100 Subject: [PATCH] Update to v1.0.1 of xk6-browser This includes some fixes for the goroutine leaks that we were seeing when we tried to create the e2e tests for the browser module in k6. --- go.mod | 2 +- go.sum | 4 ++-- .../grafana/xk6-browser/browser/registry.go | 8 +++++--- .../grafana/xk6-browser/chromium/browser_type.go | 14 -------------- .../grafana/xk6-browser/common/browser.go | 2 +- vendor/modules.txt | 2 +- 6 files changed, 10 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index eb0923b62cb1..6ae8c6b3fbd6 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible github.com/golang/protobuf v1.5.3 github.com/gorilla/websocket v1.5.0 - github.com/grafana/xk6-browser v1.0.0 + github.com/grafana/xk6-browser v1.0.1 github.com/grafana/xk6-grpc v0.1.3-0.20230717090346-fb49221e0ce1 github.com/grafana/xk6-output-prometheus-remote v0.2.2-0.20230719110733-69f101ee8ade github.com/grafana/xk6-redis v0.1.1 diff --git a/go.sum b/go.sum index 3960e4414580..79588f7e1671 100644 --- a/go.sum +++ b/go.sum @@ -179,8 +179,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grafana/xk6-browser v1.0.0 h1:P0zUsftWSYrY6GnrGOsJEh9+PdPd6/dYkFHPzoG5cUA= -github.com/grafana/xk6-browser v1.0.0/go.mod h1:Ck8IWES3Emu4CMKktQ/oD7l/JFj/1ESnDIbQGpfaoYA= +github.com/grafana/xk6-browser v1.0.1 h1:/GvMHhDMbNCEuu6ml/AIaQNtHOpj06GpKfgQJpNzPIg= +github.com/grafana/xk6-browser v1.0.1/go.mod h1:Ck8IWES3Emu4CMKktQ/oD7l/JFj/1ESnDIbQGpfaoYA= github.com/grafana/xk6-grpc v0.1.3-0.20230717090346-fb49221e0ce1 h1:SdMihJN+fkH6cO/1NeAnVxSVOnJ3ZkZ1v7FJnrcqhog= github.com/grafana/xk6-grpc v0.1.3-0.20230717090346-fb49221e0ce1/go.mod h1:iq6qHN64XgAEmDHKf0OXZ4mvoqF4Udr22fiCIXNpXA0= github.com/grafana/xk6-output-prometheus-remote v0.2.2-0.20230719110733-69f101ee8ade h1:DY8H7hMVBpP4yuKlNnPBykL+WJ4hBobwT0BG8nDcFLw= diff --git a/vendor/github.com/grafana/xk6-browser/browser/registry.go b/vendor/github.com/grafana/xk6-browser/browser/registry.go index b4eb283861f9..511e26544d7f 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/registry.go +++ b/vendor/github.com/grafana/xk6-browser/browser/registry.go @@ -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, @@ -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 @@ -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 diff --git a/vendor/github.com/grafana/xk6-browser/chromium/browser_type.go b/vendor/github.com/grafana/xk6-browser/chromium/browser_type.go index 33366a2adba1..a994fc753ad4 100644 --- a/vendor/github.com/grafana/xk6-browser/chromium/browser_type.go +++ b/vendor/github.com/grafana/xk6-browser/chromium/browser_type.go @@ -185,20 +185,6 @@ func (b *BrowserType) launch( } flags["user-data-dir"] = dataDir.Dir - go func(c context.Context) { - defer func() { - if err := dataDir.Cleanup(); err != nil { - logger.Errorf("BrowserType:Launch", "cleaning up the user data directory: %v", err) - } - }() - // There's a small chance that this might be called - // if the context is closed by the k6 runtime. To - // guarantee the cleanup we would need to orchestrate - // it correctly which https://github.com/grafana/k6/issues/2432 - // will enable once it's complete. - <-c.Done() - }(ctx) - browserProc, err := b.allocate(ctx, opts, flags, dataDir, logger) if browserProc == nil { return nil, 0, fmt.Errorf("launching browser: %w", err) diff --git a/vendor/github.com/grafana/xk6-browser/common/browser.go b/vendor/github.com/grafana/xk6-browser/common/browser.go index b9d9f4cf4e65..a0a0598c09ca 100644 --- a/vendor/github.com/grafana/xk6-browser/common/browser.go +++ b/vendor/github.com/grafana/xk6-browser/common/browser.go @@ -453,7 +453,7 @@ func (b *Browser) Close() { var closeErr *websocket.CloseError err := cdpbrowser.Close().Do(cdp.WithExecutor(b.ctx, b.conn)) if err != nil && !errors.As(err, &closeErr) { - k6ext.Panic(b.ctx, "closing the browser: %v", err) + b.logger.Errorf("Browser:Close", "closing the browser: %v", err) } } diff --git a/vendor/modules.txt b/vendor/modules.txt index fb5f4964766f..ef6c7e56c476 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -144,7 +144,7 @@ github.com/google/uuid # github.com/gorilla/websocket v1.5.0 ## explicit; go 1.12 github.com/gorilla/websocket -# github.com/grafana/xk6-browser v1.0.0 +# github.com/grafana/xk6-browser v1.0.1 ## explicit; go 1.19 github.com/grafana/xk6-browser/api github.com/grafana/xk6-browser/browser