From 26d499fe6c139579168aa18a5696d157b8c66412 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Mon, 24 Jun 2024 09:46:34 -0500 Subject: [PATCH 1/5] chore: add goleak testing for goroutine leaks --- cmd/glab/main_test.go | 8 ++++++++ go.mod | 1 + go.sum | 2 ++ 3 files changed, 11 insertions(+) diff --git a/cmd/glab/main_test.go b/cmd/glab/main_test.go index 7959a8977..3b5cfe5a8 100644 --- a/cmd/glab/main_test.go +++ b/cmd/glab/main_test.go @@ -11,6 +11,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" "gitlab.com/gitlab-org/cli/commands/cmdutils" + "go.uber.org/goleak" ) func Test_printError(t *testing.T) { @@ -101,3 +102,10 @@ x lookup https://gitlab.com/api/v4: func TestGlab(t *testing.T) { main() } + +func TestMain(m *testing.M) { + opts := []goleak.Option{ + goleak.IgnoreTopFunction("internal/poll.runtime_pollWait"), + } + goleak.VerifyTestMain(m, opts...) +} diff --git a/go.mod b/go.mod index ee2d6969e..ec50145fa 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,7 @@ require ( github.com/tidwall/pretty v1.2.1 github.com/xanzy/go-gitlab v0.105.0 github.com/zalando/go-keyring v0.2.4 + go.uber.org/goleak v1.3.0 golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f golang.org/x/sync v0.7.0 golang.org/x/term v0.21.0 diff --git a/go.sum b/go.sum index e2af1d166..3bee1170c 100644 --- a/go.sum +++ b/go.sum @@ -229,6 +229,8 @@ github.com/zalando/go-keyring v0.2.4 h1:wi2xxTqdiwMKbM6TWwi+uJCG/Tum2UV0jqaQhCa9 github.com/zalando/go-keyring v0.2.4/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -- GitLab From b13d2a1790e3ce2f766dfbc9f769e089acb503b7 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Mon, 24 Jun 2024 09:46:34 -0500 Subject: [PATCH 2/5] chore: add goleak testing for goroutine leaks --- cmd/glab/main_test.go | 8 ++++++++ go.mod | 2 ++ go.sum | 2 ++ 3 files changed, 12 insertions(+) diff --git a/cmd/glab/main_test.go b/cmd/glab/main_test.go index 7959a8977..3b5cfe5a8 100644 --- a/cmd/glab/main_test.go +++ b/cmd/glab/main_test.go @@ -11,6 +11,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" "gitlab.com/gitlab-org/cli/commands/cmdutils" + "go.uber.org/goleak" ) func Test_printError(t *testing.T) { @@ -101,3 +102,10 @@ x lookup https://gitlab.com/api/v4: func TestGlab(t *testing.T) { main() } + +func TestMain(m *testing.M) { + opts := []goleak.Option{ + goleak.IgnoreTopFunction("internal/poll.runtime_pollWait"), + } + goleak.VerifyTestMain(m, opts...) +} diff --git a/go.mod b/go.mod index ce030efc5..f18982f9f 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,8 @@ require ( github.com/tidwall/pretty v1.2.1 github.com/xanzy/go-gitlab v0.105.0 github.com/zalando/go-keyring v0.2.5 + github.com/zalando/go-keyring v0.2.4 + go.uber.org/goleak v1.3.0 golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f golang.org/x/sync v0.7.0 golang.org/x/term v0.21.0 diff --git a/go.sum b/go.sum index 537050b47..3df20e441 100644 --- a/go.sum +++ b/go.sum @@ -229,6 +229,8 @@ github.com/zalando/go-keyring v0.2.5 h1:Bc2HHpjALryKD62ppdEzaFG6VxL6Bc+5v0LYpN8L github.com/zalando/go-keyring v0.2.5/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -- GitLab From ebd8e47dfb2d4e669055812e486cc53e5e45a9d4 Mon Sep 17 00:00:00 2001 From: Kai Armstrong Date: Tue, 25 Jun 2024 09:47:53 -0500 Subject: [PATCH 3/5] go mod tidy --- go.mod | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/go.mod b/go.mod index f18982f9f..aa3e6671a 100644 --- a/go.mod +++ b/go.mod @@ -36,8 +36,8 @@ require ( github.com/tidwall/pretty v1.2.1 github.com/xanzy/go-gitlab v0.105.0 github.com/zalando/go-keyring v0.2.5 - github.com/zalando/go-keyring v0.2.4 go.uber.org/goleak v1.3.0 + golang.org/x/crypto v0.24.0 golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f golang.org/x/sync v0.7.0 golang.org/x/term v0.21.0 @@ -92,7 +92,6 @@ require ( github.com/yuin/goldmark-emoji v1.0.2 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect - golang.org/x/crypto v0.24.0 // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.19.0 // indirect golang.org/x/sys v0.21.0 // indirect -- GitLab From db15806878f23190dc7f0222fd7ac70ba946c21e Mon Sep 17 00:00:00 2001 From: Jay McCure Date: Wed, 26 Jun 2024 13:51:35 +1000 Subject: [PATCH 4/5] fix(repo archive): Close connections archive --- cmd/glab/main_test.go | 5 +---- commands/project/archive/repo_archive.go | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/glab/main_test.go b/cmd/glab/main_test.go index 3b5cfe5a8..c75329f58 100644 --- a/cmd/glab/main_test.go +++ b/cmd/glab/main_test.go @@ -104,8 +104,5 @@ func TestGlab(t *testing.T) { } func TestMain(m *testing.M) { - opts := []goleak.Option{ - goleak.IgnoreTopFunction("internal/poll.runtime_pollWait"), - } - goleak.VerifyTestMain(m, opts...) + goleak.VerifyTestMain(m) } diff --git a/commands/project/archive/repo_archive.go b/commands/project/archive/repo_archive.go index 114ed1df8..878e22de3 100644 --- a/commands/project/archive/repo_archive.go +++ b/commands/project/archive/repo_archive.go @@ -12,6 +12,7 @@ import ( "github.com/dustin/go-humanize" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" + "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" ) @@ -99,6 +100,7 @@ func NewCmdArchive(f *cmdutils.Factory) *cobra.Command { return fmt.Errorf("failed to rename tmp repos: %v", err) } fmt.Fprintln(f.IO.StdOut, "Complete...", archiveName) + api.GetClient().HTTPClient().CloseIdleConnections() return nil }, } -- GitLab From 6de48f85ea850f00da5fed4fb972fa55d1cc0f7a Mon Sep 17 00:00:00 2001 From: Jay McCure Date: Wed, 26 Jun 2024 14:12:20 +1000 Subject: [PATCH 5/5] disable keep alives --- api/client.go | 3 ++- commands/project/archive/repo_archive.go | 2 -- commands/project/archive/repo_archive_integration_test.go | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/client.go b/api/client.go index 0699c1c20..de080ce13 100644 --- a/api/client.go +++ b/api/client.go @@ -157,7 +157,8 @@ func NewClient(host, token string, allowInsecure bool, isGraphQL bool, isOAuth2 if apiClient.httpClientOverride == nil { apiClient.httpClient = &http.Client{ Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, + DisableKeepAlives: true, + Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: 5 * time.Second, KeepAlive: 5 * time.Second, diff --git a/commands/project/archive/repo_archive.go b/commands/project/archive/repo_archive.go index 878e22de3..114ed1df8 100644 --- a/commands/project/archive/repo_archive.go +++ b/commands/project/archive/repo_archive.go @@ -12,7 +12,6 @@ import ( "github.com/dustin/go-humanize" "github.com/spf13/cobra" "github.com/xanzy/go-gitlab" - "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/cmdutils" ) @@ -100,7 +99,6 @@ func NewCmdArchive(f *cmdutils.Factory) *cobra.Command { return fmt.Errorf("failed to rename tmp repos: %v", err) } fmt.Fprintln(f.IO.StdOut, "Complete...", archiveName) - api.GetClient().HTTPClient().CloseIdleConnections() return nil }, } diff --git a/commands/project/archive/repo_archive_integration_test.go b/commands/project/archive/repo_archive_integration_test.go index 4d518f685..d537e2043 100644 --- a/commands/project/archive/repo_archive_integration_test.go +++ b/commands/project/archive/repo_archive_integration_test.go @@ -79,6 +79,7 @@ func Test_repoArchive_Integration(t *testing.T) { if err != nil { t.Log(err) + t.Log(string(b)) if !tt.wantErr { t.Fatal(err) } -- GitLab