Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Fix goroutine leak bug in DoDownloadTimeout #1565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timmyyuan
Copy link

Ⅰ. Describe what this PR did

This PR fix a goroutine leak bug in DoDownloadTimeout

Ⅱ. Does this pull request fix one issue?

NONE

Ⅲ. Why don't you add test cases (unit test/integration test)?

This fix is already covered by TestDoDownloadTimeout

Ⅳ. Describe how to verify it

In the original code, DoDownloadTimeout has a potential goroutine leak in rare goroutine intervening. It can be verified by using https://github.com/uber-go/goleak if we instrument the entry of func Test(t *testing.T) in dfget/core/downloader/downloader_test.go and then run TestDoDownloadTimeout enough times:

go test github.com/dragonflyoss/Dragonfly/dfget/core/downloader -gocheck.f=TestDoDownloadTimeout

This command results in :

time="2021-11-01T13:37:27+08:00" level=warning msg="invalid download timeout(0.000s), use default:(300.000s)"
leaks.go:78: found unexpected goroutines:
    [Goroutine 8 in state chan send, with github.com/dragonflyoss/Dragonfly/dfget/core/downloader.DoDownloadTimeout.func1 on top of the stack:
    goroutine 8 [chan send]:
    github.com/dragonflyoss/Dragonfly/dfget/core/downloader.DoDownloadTimeout.func1()
            /home/yuanting/work/dev/goprojects/dragonfly/dfget/core/downloader/downloader.go:56 +0x12f
    created by github.com/dragonflyoss/Dragonfly/dfget/core/downloader.DoDownloadTimeout
            /home/yuanting/work/dev/goprojects/dragonfly/dfget/core/downloader/downloader.go:55 +0x205
        ]

Ⅴ. Special notes for reviews

@timmyyuan timmyyuan force-pushed the ting/fix-goroutine-leak branch from 9d765ef to aa4e2c3 Compare November 1, 2021 06:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant