Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goroutine leaks #237

Open
Tracked by #1138
inancgumus opened this issue Feb 15, 2022 · 0 comments
Open
Tracked by #1138

Goroutine leaks #237

inancgumus opened this issue Feb 15, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@inancgumus
Copy link
Member

inancgumus commented Feb 15, 2022

It seems like we have Goroutine leaks.

I added Uber's goleak to the tests package's TestMain:

func TestMain(m *testing.M) {
	goleak.VerifyTestMain(m)
}

Then, I ran a simple test:

go test ./tests -run='TestBrowserNewPage$'
time="2022-02-15T11:06:40+03:00" level=error msg="err:websocket: close 1006 (abnormal closure): unexpected EOF" category="Connection:handleIOError" elapsed="0 ms" goroutine=12
goleak: Errors on successful test run: found unexpected goroutines:
[Goroutine 24 in state chan receive, with github.com/grafana/xk6-browser/common.NewBrowserProcess.func1 on top of the stack:
goroutine 24 [chan receive]:
github.com/grafana/xk6-browser/common.NewBrowserProcess.func1(0x140000b0240)
	/Users/inanc/grafana/k6b/common/browser_process.go:66 +0x30
created by github.com/grafana/xk6-browser/common.NewBrowserProcess
	/Users/inanc/grafana/k6b/common/browser_process.go:63 +0x13c

 Goroutine 25 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 25 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140000ea2c0, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 11 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 11 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x1400038eb80, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 12 in state select, with github.com/grafana/xk6-browser/common.(*Connection).handleIOError on top of the stack:
goroutine 12 [select]:
github.com/grafana/xk6-browser/common.(*Connection).handleIOError(0x140002d1180, {0x101ad5f60, 0x102542720})
	/Users/inanc/grafana/k6b/common/connection.go:217 +0x13c
github.com/grafana/xk6-browser/common.(*Connection).recvLoop(0x140002d1180)
	/Users/inanc/grafana/k6b/common/connection.go:260 +0x107c
created by github.com/grafana/xk6-browser/common.NewConnection
	/Users/inanc/grafana/k6b/common/connection.go:147 +0x2e8

 Goroutine 13 in state select, with github.com/grafana/xk6-browser/common.(*Connection).sendLoop on top of the stack:
goroutine 13 [select]:
github.com/grafana/xk6-browser/common.(*Connection).sendLoop(0x140002d1180)
	/Users/inanc/grafana/k6b/common/connection.go:416 +0x158
created by github.com/grafana/xk6-browser/common.NewConnection
	/Users/inanc/grafana/k6b/common/connection.go:148 +0x308

 Goroutine 14 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 14 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x1400038ebc0, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 15 in state select, with github.com/grafana/xk6-browser/common.(*Browser).initEvents.func1 on top of the stack:
goroutine 15 [select]:
github.com/grafana/xk6-browser/common.(*Browser).initEvents.func1({0x101aee078, 0x1400038ec00}, 0x140000a2720, 0x1400010e000)
	/Users/inanc/grafana/k6b/common/browser.go:174 +0x88
created by github.com/grafana/xk6-browser/common.(*Browser).initEvents
	/Users/inanc/grafana/k6b/common/browser.go:172 +0x154

 Goroutine 38 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 38 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x1400054e040, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 52 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 52 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x1400038ed40, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 56 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 56 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x1400038ed80, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 72 in state select, with github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer.func1 on top of the stack:
goroutine 72 [select]:
github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer.func1(0x14000102b60)
	/Users/inanc/grafana/k6b/common/frame.go:288 +0xa8
created by github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer
	/Users/inanc/grafana/k6b/common/frame.go:287 +0x170

 Goroutine 57 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 57 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x1400038ee00, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 58 in state select, with github.com/grafana/xk6-browser/common.(*NetworkManager).handleEvents on top of the stack:
goroutine 58 [select]:
github.com/grafana/xk6-browser/common.(*NetworkManager).handleEvents(0x140001b8180, 0x140000a2c60)
	/Users/inanc/grafana/k6b/common/network_manager.go:360 +0x84
github.com/grafana/xk6-browser/common.(*NetworkManager).initEvents.func1(0x140001b8180, 0x140000a2c60)
	/Users/inanc/grafana/k6b/common/network_manager.go:354 +0x30
created by github.com/grafana/xk6-browser/common.(*NetworkManager).initEvents
	/Users/inanc/grafana/k6b/common/network_manager.go:353 +0x12c

 Goroutine 184 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 184 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140000ea9c0, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 40 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 40 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x1400054e100, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 71 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 71 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140005c20c0, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 149 in state select, with github.com/grafana/xk6-browser/common.(*NetworkManager).handleEvents on top of the stack:
goroutine 149 [select]:
github.com/grafana/xk6-browser/common.(*NetworkManager).handleEvents(0x140005e80c0, 0x140005b8de0)
	/Users/inanc/grafana/k6b/common/network_manager.go:360 +0x84
github.com/grafana/xk6-browser/common.(*NetworkManager).initEvents.func1(0x140005e80c0, 0x140005b8de0)
	/Users/inanc/grafana/k6b/common/network_manager.go:354 +0x30
created by github.com/grafana/xk6-browser/common.(*NetworkManager).initEvents
	/Users/inanc/grafana/k6b/common/network_manager.go:353 +0x12c

 Goroutine 147 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 147 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140005c2380, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 148 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 148 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140005c2400, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 106 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 106 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x1400019c100, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 107 in state select, with github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer.func1 on top of the stack:
goroutine 107 [select]:
github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer.func1(0x140001e6680)
	/Users/inanc/grafana/k6b/common/frame.go:288 +0xa8
created by github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer
	/Users/inanc/grafana/k6b/common/frame.go:287 +0x170

 Goroutine 242 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 242 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140005c29c0, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 187 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 187 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140000eb040, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 191 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 191 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140000eb080, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 192 in state select, with github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll on top of the stack:
goroutine 192 [select]:
github.com/grafana/xk6-browser/common.(*BaseEventEmitter).syncAll(0x140000eb100, {0x101aee120, 0x140000f2060})
	/Users/inanc/grafana/k6b/common/event_emitter.go:136 +0xa4
created by github.com/grafana/xk6-browser/common.NewBaseEventEmitter
	/Users/inanc/grafana/k6b/common/event_emitter.go:126 +0x130

 Goroutine 193 in state select, with github.com/grafana/xk6-browser/common.(*NetworkManager).handleEvents on top of the stack:
goroutine 193 [select]:
github.com/grafana/xk6-browser/common.(*NetworkManager).handleEvents(0x140001443c0, 0x140000dd860)
	/Users/inanc/grafana/k6b/common/network_manager.go:360 +0x84
github.com/grafana/xk6-browser/common.(*NetworkManager).initEvents.func1(0x140001443c0, 0x140000dd860)
	/Users/inanc/grafana/k6b/common/network_manager.go:354 +0x30
created by github.com/grafana/xk6-browser/common.(*NetworkManager).initEvents
	/Users/inanc/grafana/k6b/common/network_manager.go:353 +0x12c

 Goroutine 243 in state select, with github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer.func1 on top of the stack:
goroutine 243 [select]:
github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer.func1(0x140005f2b60)
	/Users/inanc/grafana/k6b/common/frame.go:288 +0xa8
created by github.com/grafana/xk6-browser/common.(*Frame).startNetworkIdleTimer
	/Users/inanc/grafana/k6b/common/frame.go:287 +0x170
]
FAIL	github.com/grafana/xk6-browser/tests	1.315s
FAIL

Since this is a single test, there might be other leaks as well.

Main suspects are:

  • NewBrowserProcess
  • (*Connection).handleIOError
  • (*Connection).sendLoop
  • (*Browser).initEvents
  • (*Frame).startNetworkIdleTimer
  • (*NetworkManager).handleEvents
  • (*BaseEventEmitter).syncAll (but I believe this might be because of an incorrect usage of it (like: not returning from the handler))

I discovered before that handleIOError is problematic but didn't look into it yet.

@inancgumus inancgumus added the bug Something isn't working label Feb 15, 2022
@inancgumus inancgumus added the next Might be eligible for the next planning (not guaranteed!) label Nov 30, 2023
@inancgumus inancgumus removed the next Might be eligible for the next planning (not guaranteed!) label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants