moby / libnetwork

networking for containers
Apache License 2.0
2.16k stars 881 forks source link

[Bug]:A potential goroutine leak in libnetwork/drivers/overlay/peerdb.go #2680

Closed xuxiaofan1203 closed 1 month ago

xuxiaofan1203 commented 7 months ago

Hello @olljanat, the libnetwork is useful, but I found a bug when I used it, I think we can fix it. In the test file https://github.com/moby/libnetwork/blob/3797618f9a38372e8107d8c06f6ae199e1133ae8/drivers/overlay/overlay_test.go#L134-L144 After the Init has executed and the ctx and cancel are created at https://github.com/moby/libnetwork/blob/3797618f9a38372e8107d8c06f6ae199e1133ae8/drivers/overlay/overlay.go#L75-L77 There is no cancelFunc to awaken the ctx.Done() at https://github.com/moby/libnetwork/blob/3797618f9a38372e8107d8c06f6ae199e1133ae8/drivers/overlay/peerdb.go#L280 So the goroutine will block, and you can use the goleak to reproduce the bug like this

func TestOverlayType(t *testing.T) {
    defer goleak.VerifyNone(t)
    dt := &driverTester{t: t}
    if err := Init(dt, nil); err != nil {
        t.Fatal(err)
    }

    if dt.d.Type() != testNetworkType {
        t.Fatalf("Expected Type() to return %q. Instead got %q", testNetworkType,
            dt.d.Type())
    }
}

1712385445732 And I think we can fix the bug by calling the cleanupDriver() after the init() gets executed.

olljanat commented 6 months ago

@xuxiaofan1203 please note what is wrote to readme:

Warning libnetwork was moved to https://github.com/moby/moby/tree/master/libnetwork

So double check if same issue still exists latest code int there and report it there if it does. Also note that I'm not Moby maintainer but they are looking for that there in there.

xuxiaofan1203 commented 6 months ago

@xuxiaofan1203 please note what is wrote to readme:

Warning libnetwork was moved to https://github.com/moby/moby/tree/master/libnetwork

So double check if same issue still exists latest code int there and report it there if it does. Also note that I'm not Moby maintainer but they are looking for that there in there.

Thank you for your reply and help, I will check again there. And I'm sorry to bother you.

akerouanton commented 1 month ago

As already noted by @olljanat, this repo is now defunct and not actively watched by maintainers. Also, it seems this goroutine leak only exists in an isolated test due to how it's written. So let me close this issue.