-
Notifications
You must be signed in to change notification settings - Fork 21.5k
Open
Labels
Description
System information
OS & Version: Linux & Latest version
Expected behaviour
There is no goroutine leak.
Actual behaviour
Under specific interleaving of synchronous operations, there is a goroutine leak due to blocking at
go-ethereum/core/state/snapshot/generate.go
Line 705 in f4817b7
| abort = <-dl.genAbort |
Steps to reproduce the behaviour
1.Add time.Sleep(time.Millisecond * 300) before
go-ethereum/ethdb/memorydb/memorydb.go
Line 167 in f4817b7
| db.lock.RLock() |
time.Sleep(time.Millisecond * 300)
db.lock.RLock()
2.Add time.Sleep(200 * time.Millisecond) before
go-ethereum/ethdb/memorydb/memorydb.go
Line 277 in f4817b7
| b.db.lock.Lock() |
time.Sleep(200 * time.Millisecond)
b.db.lock.Lock()
3.Modify case <-time.After(3 * time.Second): to time.After(300 * time.Millisecond), which make Snapshot generation fail easily.
| case <-time.After(3 * time.Second): |
The three steps is to make the specific interleaving happen.
4.Using goleak to detect the goroutine leak in the test.
| func TestGeneration(t *testing.T) { |
func TestGeneration(t *testing.T) {
defer goleak.VerifyNone(t)
Backtrace
=== RUN TestGeneration
generate_test.go:80: Snapshot generation failed
generate_test.go:82: snaproot: 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 != trieroot #e3712f1a226f3782caca78ca770ccc19ee000552813a9f59d479f8611db9b1fd
panic.go:631: found unexpected goroutines:
[Goroutine 21 in state chan receive, with github.com/ethereum/go-ethereum/core/state/snapshot.(*diskLayer).generate on top of the stack:
github.com/ethereum/go-ethereum/core/state/snapshot.(*diskLayer).generate(0xc000174480, 0xc000288000)
/home/song2048/桌面/goProject/src/go-ethereum-master/core/state/snapshot/generate.go:705 +0x5fd
created by github.com/ethereum/go-ethereum/core/state/snapshot.generateSnapshot in goroutine 20
/home/song2048/桌面/goProject/src/go-ethereum-master/core/state/snapshot/generate.go:79 +0x354
]
--- FAIL: TestGeneration (1.46s)
FAIL