From ec84e535e4121578a3c226d33bb4c17ab8e67c6a Mon Sep 17 00:00:00 2001 From: Cu pid Date: Wed, 21 Jan 2026 12:15:06 +0100 Subject: [PATCH 1/7] fix: resolve context leak, unseeded jitter, and broken test utility --- internal/requestconfig/requestconfig.go | 15 ++++++++------- internal/testutil/testutil.go | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/requestconfig/requestconfig.go b/internal/requestconfig/requestconfig.go index c828073..899bb0c 100644 --- a/internal/requestconfig/requestconfig.go +++ b/internal/requestconfig/requestconfig.go @@ -407,7 +407,8 @@ func retryDelay(res *http.Response, retryCount int) time.Duration { delay = maxDelay } - jitter := rand.Int63n(int64(delay / 4)) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + jitter := r.Int63n(int64(delay / 4)) delay -= time.Duration(jitter) return delay } @@ -466,12 +467,6 @@ func (cfg *RequestConfig) Execute() (err error) { ctx := cfg.Request.Context() if cfg.RequestTimeout != time.Duration(0) && isBeforeContextDeadline(time.Now().Add(cfg.RequestTimeout), ctx) { ctx, cancel = context.WithTimeout(ctx, cfg.RequestTimeout) - defer func() { - // The cancel function is nil if it was handed off to be handled in a different scope. - if cancel != nil { - cancel() - } - }() } req := cfg.Request.Clone(ctx) @@ -480,6 +475,12 @@ func (cfg *RequestConfig) Execute() (err error) { } res, err = handler(req) + + // Close the timeout context for this attempt if one was created + if cancel != nil { + cancel() + cancel = nil + } if ctx != nil && ctx.Err() != nil { return ctx.Err() } diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go index 826d266..9f431ad 100644 --- a/internal/testutil/testutil.go +++ b/internal/testutil/testutil.go @@ -19,9 +19,9 @@ func CheckTestServer(t *testing.T, url string) bool { t.Skip("The test will not run without a mock Prism server running against your OpenAPI spec") return false } - t.Errorf("The test will not run without a mock Prism server running against your OpenAPI spec. You can set the environment variable %s to true to skip running any tests that require the mock server", SKIP_MOCK_TESTS) - return false } + t.Errorf("The test will not run without a mock Prism server running against your OpenAPI spec. You can set the environment variable %s to true to skip running any tests that require the mock server. Error: %s", SKIP_MOCK_TESTS, err) + return false } return true } From c1a1ee4791f9a520eb85f1f4d5b68531d8c08413 Mon Sep 17 00:00:00 2001 From: ka zie Date: Wed, 21 Jan 2026 13:15:23 +0100 Subject: [PATCH 2/7] Change remote organization name in CLA workflow --- .github/workflows/cla.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index d35f761..2d5de4f 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -29,9 +29,9 @@ jobs: path-to-document: "https://github.com/codecarrotlabs/cla-document/blob/main/readme.md" branch: "main" allowlist: mittalyashu,renovate[bot],dependabot[bot] - remote-organization-name: "logchimp" + remote-organization-name: "lupppig" remote-repository-name: "cla-signatures" custom-notsigned-prcomment: | Thank you for your submission, we really appreciate it. This open-source project (“Projects”) made available by Shinkly Private Limited (SPL). We ask that you sign our [Contributor License Agreement](https://github.com/codecarrotlabs/cla-document/blob/main/readme.md) before we can accept your contribution. You can sign the CLA by just posting a Pull Request comment same as the below format. If you have any questions respecting this Agreement, please contact [opensource@codecarrot.net](mailto:opensource@codecarrot.net). signed-commit-message: | - $contributorName has signed the CLA in $pullRequestNo \ No newline at end of file + $contributorName has signed the CLA in $pullRequestNo From b237cc7a891c35ee50a162d6ff3988b62e8aadf7 Mon Sep 17 00:00:00 2001 From: ka zie Date: Wed, 21 Jan 2026 13:21:41 +0100 Subject: [PATCH 3/7] Update remote organization name in CLA workflow --- .github/workflows/cla.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 2d5de4f..39aa369 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -29,7 +29,7 @@ jobs: path-to-document: "https://github.com/codecarrotlabs/cla-document/blob/main/readme.md" branch: "main" allowlist: mittalyashu,renovate[bot],dependabot[bot] - remote-organization-name: "lupppig" + remote-organization-name: "logchimp" remote-repository-name: "cla-signatures" custom-notsigned-prcomment: | Thank you for your submission, we really appreciate it. This open-source project (“Projects”) made available by Shinkly Private Limited (SPL). We ask that you sign our [Contributor License Agreement](https://github.com/codecarrotlabs/cla-document/blob/main/readme.md) before we can accept your contribution. You can sign the CLA by just posting a Pull Request comment same as the below format. If you have any questions respecting this Agreement, please contact [opensource@codecarrot.net](mailto:opensource@codecarrot.net). From 893137dd949db45d86facc8a7dea0c72a2966d9e Mon Sep 17 00:00:00 2001 From: ka zie Date: Sun, 25 Jan 2026 12:24:01 +0100 Subject: [PATCH 4/7] Update signed commit message in CLA workflow --- .github/workflows/cla.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 39aa369..55a401c 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -34,4 +34,4 @@ jobs: custom-notsigned-prcomment: | Thank you for your submission, we really appreciate it. This open-source project (“Projects”) made available by Shinkly Private Limited (SPL). We ask that you sign our [Contributor License Agreement](https://github.com/codecarrotlabs/cla-document/blob/main/readme.md) before we can accept your contribution. You can sign the CLA by just posting a Pull Request comment same as the below format. If you have any questions respecting this Agreement, please contact [opensource@codecarrot.net](mailto:opensource@codecarrot.net). signed-commit-message: | - $contributorName has signed the CLA in $pullRequestNo + Darasimi Kelani has signed the CLA in pull request #14 From eed53deab8176e9f8a8e28d5409e8df85fd78c45 Mon Sep 17 00:00:00 2001 From: ka zie Date: Sun, 25 Jan 2026 12:29:02 +0100 Subject: [PATCH 5/7] Modify signed commit message in CLA workflow Updated signed commit message template in CLA workflow. --- .github/workflows/cla.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 55a401c..39aa369 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -34,4 +34,4 @@ jobs: custom-notsigned-prcomment: | Thank you for your submission, we really appreciate it. This open-source project (“Projects”) made available by Shinkly Private Limited (SPL). We ask that you sign our [Contributor License Agreement](https://github.com/codecarrotlabs/cla-document/blob/main/readme.md) before we can accept your contribution. You can sign the CLA by just posting a Pull Request comment same as the below format. If you have any questions respecting this Agreement, please contact [opensource@codecarrot.net](mailto:opensource@codecarrot.net). signed-commit-message: | - Darasimi Kelani has signed the CLA in pull request #14 + $contributorName has signed the CLA in $pullRequestNo From 32c9a4db6685e70742aa9ab4210f78ca6a45e93d Mon Sep 17 00:00:00 2001 From: Cu pid Date: Sun, 25 Jan 2026 21:34:42 +0100 Subject: [PATCH 6/7] fix: resolve context and connection leaks in request handler and test utils --- internal/requestconfig/requestconfig.go | 20 ++++++++++++++++++++ internal/testutil/testutil.go | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/requestconfig/requestconfig.go b/internal/requestconfig/requestconfig.go index 899bb0c..c62e47f 100644 --- a/internal/requestconfig/requestconfig.go +++ b/internal/requestconfig/requestconfig.go @@ -492,6 +492,10 @@ func (cfg *RequestConfig) Execute() (err error) { if cfg.Request.GetBody != nil { cfg.Request.Body, err = cfg.Request.GetBody() if err != nil { + if cancel != nil { + cancel() + cancel = nil + } return err } } @@ -505,6 +509,10 @@ func (cfg *RequestConfig) Execute() (err error) { if res != nil && res.Body != nil { res.Body.Close() } + if cancel != nil { + cancel() + cancel = nil + } time.Sleep(retryDelay(res, retryCount)) } @@ -522,12 +530,20 @@ func (cfg *RequestConfig) Execute() (err error) { // If there was a connection error in the final request or any other transport error, // return that early without trying to coerce into an APIError. if err != nil { + if cancel != nil { + cancel() + cancel = nil + } return err } if res.StatusCode >= 400 { contents, err := io.ReadAll(res.Body) res.Body.Close() + if cancel != nil { + cancel() + cancel = nil + } if err != nil { return err } @@ -559,6 +575,10 @@ func (cfg *RequestConfig) Execute() (err error) { contents, err := io.ReadAll(res.Body) res.Body.Close() + if cancel != nil { + cancel() + cancel = nil + } if err != nil { return fmt.Errorf("error reading response body: %w", err) } diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go index 9f431ad..a7506b8 100644 --- a/internal/testutil/testutil.go +++ b/internal/testutil/testutil.go @@ -8,7 +8,11 @@ import ( ) func CheckTestServer(t *testing.T, url string) bool { - if _, err := http.Get(url); err != nil { + res, err := http.Get(url) + if err == nil { + res.Body.Close() + } + if err != nil { const SKIP_MOCK_TESTS = "SKIP_MOCK_TESTS" if str, ok := os.LookupEnv(SKIP_MOCK_TESTS); ok { skip, err := strconv.ParseBool(str) From 3597209ad094df221ad172fe34ee3924156148df Mon Sep 17 00:00:00 2001 From: Cu pid Date: Sun, 25 Jan 2026 21:44:53 +0100 Subject: [PATCH 7/7] fix: resolve context leak and revert workflow changes --- .github/workflows/cla.yml | 2 +- internal/requestconfig/requestconfig.go | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 39aa369..d35f761 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -34,4 +34,4 @@ jobs: custom-notsigned-prcomment: | Thank you for your submission, we really appreciate it. This open-source project (“Projects”) made available by Shinkly Private Limited (SPL). We ask that you sign our [Contributor License Agreement](https://github.com/codecarrotlabs/cla-document/blob/main/readme.md) before we can accept your contribution. You can sign the CLA by just posting a Pull Request comment same as the below format. If you have any questions respecting this Agreement, please contact [opensource@codecarrot.net](mailto:opensource@codecarrot.net). signed-commit-message: | - $contributorName has signed the CLA in $pullRequestNo + $contributorName has signed the CLA in $pullRequestNo \ No newline at end of file diff --git a/internal/requestconfig/requestconfig.go b/internal/requestconfig/requestconfig.go index c62e47f..176321b 100644 --- a/internal/requestconfig/requestconfig.go +++ b/internal/requestconfig/requestconfig.go @@ -476,19 +476,17 @@ func (cfg *RequestConfig) Execute() (err error) { res, err = handler(req) - // Close the timeout context for this attempt if one was created - if cancel != nil { - cancel() - cancel = nil - } if ctx != nil && ctx.Err() != nil { + if cancel != nil { + cancel() + cancel = nil + } return ctx.Err() } if !shouldRetry(cfg.Request, res) || retryCount >= cfg.MaxRetries { break } - // Prepare next request and wait for the retry delay if cfg.Request.GetBody != nil { cfg.Request.Body, err = cfg.Request.GetBody() if err != nil { @@ -505,7 +503,6 @@ func (cfg *RequestConfig) Execute() (err error) { break } - // Close the response body before retrying to prevent connection leaks if res != nil && res.Body != nil { res.Body.Close() }