Skip to content

A potential goroutine leak in core/state/snapshot/generate.go #33233

@user12031

Description

@user12031

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

abort = <-dl.genAbort

Steps to reproduce the behaviour

1.Add time.Sleep(time.Millisecond * 300) before

db.lock.RLock()

time.Sleep(time.Millisecond * 300)
db.lock.RLock()

2.Add time.Sleep(200 * time.Millisecond) before

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions