Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close leaked response bodies #43

Merged
merged 3 commits into from
Dec 13, 2024
Merged

Close leaked response bodies #43

merged 3 commits into from
Dec 13, 2024

Conversation

andrewstucki
Copy link
Contributor

This ensures that we close all response bodies (or documents when they should be closed, but aren't). Working on some tests/validations, but throwing this up here for some eyes.

Copy link
Contributor

@gene-redpanda gene-redpanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

mutex.Lock()
defer mutex.Unlock()

if resURL != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda seems like moving maybeUnmarshalRespInto into this closure would make everything much easier to think about. (That and an errgroup would be much better suited than a multierrgroup but I'll pick one hill to die on here...)

var succeeded atomic.Bool

// ...

defer myRes.Body.Close()

if !succeeded.CompareAndSwap(false, true) {
   // Someone else beat us.  
  return nil
}

// Unmarshal the successful call.
return maybeUnmarshalRespInto(method, resURL, res, into)

// ... Out of closure

if succeeded.Load() {
  // Success or error un unmarshal
}
return grp.Errs()

Copy link
Contributor

@chrisseto chrisseto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, meant to hit approve.

@andrewstucki
Copy link
Contributor Author

@chrisseto @gene-redpanda @RafalKorepta can y'all re-review with the janky test I added with a global response tracker in our tests to ensure we're actually closing connections? I couldn't get the sendAll use-case tested, but that looks like it's for old Redpanda instances as a fallback, but the added test fails without the change due to a non 2xx response.

Copy link
Contributor

@chrisseto chrisseto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice testing solution!

@@ -69,6 +69,10 @@ type (
NopAuth struct{}
)

// responseWrapper functions as a testing mechanism for ensuring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also consider adding an Opt that allows setting the transport (line 190 in admin.go) and wrap this up in a transport wrapper. Then we'd catch any leaks that might be stemming from pester or a misuse there of.

This alone is a huge improvement though!

@andrewstucki andrewstucki merged commit 113b964 into main Dec 13, 2024
2 checks passed
@andrewstucki andrewstucki deleted the close-leaked-responses branch December 13, 2024 22:36
RafalKorepta added a commit to redpanda-data/redpanda-operator that referenced this pull request Dec 16, 2024
In latest rpadmin the go routine leak was fixed.

redpanda-data/common-go#43
RafalKorepta added a commit to redpanda-data/redpanda-operator that referenced this pull request Dec 16, 2024
In latest rpadmin the go routine leak was fixed.

redpanda-data/common-go#43
RafalKorepta added a commit to redpanda-data/redpanda-operator that referenced this pull request Dec 16, 2024
In latest rpadmin the go routine leak was fixed.

redpanda-data/common-go#43
RafalKorepta added a commit to redpanda-data/redpanda-operator that referenced this pull request Dec 16, 2024
In latest rpadmin the go routine leak was fixed.

redpanda-data/common-go#43
RafalKorepta added a commit to redpanda-data/redpanda-operator that referenced this pull request Dec 16, 2024
In latest rpadmin the go routine leak was fixed.

redpanda-data/common-go#43
RafalKorepta added a commit to redpanda-data/redpanda-operator that referenced this pull request Dec 17, 2024
In latest rpadmin the go routine leak was fixed.

redpanda-data/common-go#43
RafalKorepta added a commit to redpanda-data/redpanda-operator that referenced this pull request Dec 17, 2024
In latest rpadmin the go routine leak was fixed.

redpanda-data/common-go#43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants