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

A potential goroutine leak in server_test.go #1610

Open
xuxiaofan1203 opened this issue Oct 26, 2024 · 2 comments
Open

A potential goroutine leak in server_test.go #1610

xuxiaofan1203 opened this issue Oct 26, 2024 · 2 comments

Comments

@xuxiaofan1203
Copy link

For the lock and condition variable, if the testShutdownNotify.Wait() get executed very late, some goroutine will leak.

dns/server_test.go

Lines 733 to 735 in b77d1ed

testShutdownNotify.L.Lock()
testShutdownNotify.Wait()
testShutdownNotify.L.Unlock()

The interleaved sequence that trigger bugs can be reproduced by adding time.Sleep to make Wait() executes late like this:

testShutdownNotify.L.Lock()
time.Sleep(time.Second)
testShutdownNotify.Wait()
testShutdownNotify.L.Unlock()

After that, you can use goleak to reproduce the bug in the test function.

func TestInProgressQueriesAtShutdownTCP(t *testing.T) {

Some outputs about the bug from goleak are as follows:

Goroutine 85 in state sync.Cond.Wait, with sync.runtime_notifyListWait on top of the stack:
        sync.runtime_notifyListWait(0xc00007e1d0, 0x0)
        	/usr/local/go/src/runtime/sema.go:587 +0x159
        sync.(*Cond).Wait(0x3b9aca00?)
        	/usr/local/go/src/sync/cond.go:71 +0x85
        github.com/miekg/dns.checkInProgressQueriesAtShutdownServer.func2({0x8b3e30, 0xc000038c80}, 0xc0000f54d0)
        	/home/song2048/桌面/goProject/src/github.com/system-pclub/GCatch/GCatch/testdata/src/github.com/dns/server_test.go:736 +0x9a
@miekg
Copy link
Owner

miekg commented Nov 22, 2024

... in the test functions?? Do you have an PR?

@xuxiaofan1203
Copy link
Author

xuxiaofan1203 commented Nov 23, 2024

... in the test functions?? Do you have an PR?

Yes, the bug is in the test functions mentioned above. I found the bug, but I'm not sure how to fix it. So I haven't submitted an PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants