Skip to content

workhorse: add some Goroutine leak detection in tests

Stan Hu requested to merge sh-add-goroutine-leak-checks into master

What does this MR do and why?

This is a follow-up to !156420 (merged). We had a long-standing Goroutine leak, but for some reason it only became a a problem after the upgrade to Go 1.22.3 from 1.21.9 (UPDATED: explanation here). This adds some Goroutine leak checks in some of the artifact upload tests.

Relates to

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Revert !156420 (merged): git revert -m 1 1a851b4174253553b0fe468b10ea8c4e92a3e6bb
  2. This should flag the Goroutine leaks:
% go test -timeout 30s -run ^(TestDownloadingFromValidArchive|TestDownloadingFromValidHTTPArchive|TestDownloadingNonExistingFile|TestDownloadingFromInvalidArchive|TestIncompleteApiResponse|TestDownloadingFromNonExistingHTTPArchive)$ gitlab.com/gitlab-org/gitlab/workhorse/internal/artifacts
time="2024-06-18T13:40:29-07:00" level=info msg="SendEntry: sending" archive=/var/folders/k4/mbnh565n4wg6xpbqv45tv91h0000gn/T/uploads3359004673 correlation_id= entry="dGVzdC50eHQ=" path=/url/path
failed to kill process group: exec: Wait was already called
--- FAIL: TestDownloadingFromValidArchive (0.76s)
    /Users/stanhu/gdk-ee/gitlab/workhorse/internal/artifacts/testhelper.go:155: found unexpected goroutines:
        [Goroutine 51 in state select, with io.(*pipe).read on top of the stack:
        io.(*pipe).read(0x140002fa180, {0x1400028e000, 0x10000, 0x0?})
        	/Users/stanhu/.asdf/installs/golang/1.22.4/go/src/io/pipe.go:57 +0x84
        io.(*PipeReader).Read(0x100f67000?, {0x1400028e000?, 0x140003ad678?, 0x10014cdfc?})
        	/Users/stanhu/.asdf/installs/golang/1.22.4/go/src/io/pipe.go:134 +0x24
        bufio.(*Scanner).Scan(0x140003ad718)
        	/Users/stanhu/.asdf/installs/golang/1.22.4/go/src/bufio/scan.go:219 +0x7d0
        github.com/sirupsen/logrus.(*Entry).writerScanner(0x140000d2bd0, 0x140002fa180, 0x140000d4790)
        	/Users/stanhu/.asdf/installs/golang/1.22.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/writer.go:86 +0xec
        created by github.com/sirupsen/logrus.(*Entry).WriterLevel in goroutine 50
        	/Users/stanhu/.asdf/installs/golang/1.22.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/writer.go:57 +0x34c
        ]
Edited by Ash McKenzie

Merge request reports