You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to reproduce:
You can use goleak testing the function to reproduce the bug. For the test function , The newMockRaft( ) is called four times, but only one c.Get(3).Stop() get exectued. So goroutines leak.
leaks.go:78: found unexpected goroutines:
[Goroutine 9 in state select, with github.com/moby/swarmkit/v2/manager/state/raft/transport.(*Transport).run on top of the stack:
goroutine 9 [select]:
github.com/moby/swarmkit/v2/manager/state/raft/transport.(*Transport).run(0xc0000365f0, {0xe26d20, 0xc0000365a0})
/home/song2048/桌面/goProject/src/GoPV/GoPV/testdata/real-GoProjects/src/github.com/swarmkit/manager/state/raft/transport/transport.go:111 +0x1e7
created by github.com/moby/swarmkit/v2/manager/state/raft/transport.New in goroutine 8
/home/song2048/桌面/goProject/src/GoPV/GoPV/testdata/real-GoProjects/src/github.com/swarmkit/manager/state/raft/transport/transport.go:80 +0x29c
How to fix the bug:
For the test function, we should call stop() three times at the end of the function to avoid leaking goroutines.
c.Get(1).Stop()
c.Get(2).Stop()
nr.Stop()
The text was updated successfully, but these errors were encountered:
xuxiaofan1203
changed the title
A goroutine leak in manager/state/raft/transport/mock_raft_test.go
A goroutine leak in manager/state/raft/transport/transport_test.go
Oct 28, 2024
When call New() at
swarmkit/manager/state/raft/transport/mock_raft_test.go
Line 68 in e8ecf83
A goroutine is created to execute run() in New()
swarmkit/manager/state/raft/transport/transport.go
Line 79 in e8ecf83
And the run() can return when
case <-ctx.Done()
get executedswarmkit/manager/state/raft/transport/transport.go
Lines 100 to 105 in e8ecf83
However, there is no tr.Stop() to cancel the context after calling New() sometimes. So the goroutine will block forever and leak.
swarmkit/manager/state/raft/transport/transport.go
Lines 119 to 122 in e8ecf83
How to reproduce:
You can use goleak testing the function to reproduce the bug. For the test function , The newMockRaft( ) is called four times, but only one
c.Get(3).Stop()
get exectued. So goroutines leak.swarmkit/manager/state/raft/transport/transport_test.go
Line 214 in e8ecf83
swarmkit/manager/state/raft/transport/transport_test.go
Line 230 in e8ecf83
The partial output is as follows:
How to fix the bug:
For the test function, we should call stop() three times at the end of the function to avoid leaking goroutines.
The text was updated successfully, but these errors were encountered: