Repository navigation
pkg/storage: fix goroutine leak when chunked release decoding fails #573
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ import ( | |
| "encoding/json" | ||
| "fmt" | ||
| "maps" | ||
| "runtime" | ||
| "strings" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
@@ -95,6 +97,26 @@ var _ = Describe("chunkedSecrets", func() { | |
| _, err := maxReadDriver.Get(releaseKey(rel)) | ||
| Expect(err).To(MatchError(ContainSubstring("release too large"))) | ||
| }) | ||
| It("should not leak goroutines if the release fails to decode", func() { | ||
| corruptIndex := &corev1.Secret{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "corrupt-release.v1"}, | ||
| Type: SecretTypeChunkedIndex, | ||
| Data: map[string][]byte{ | ||
| "extraChunks": []byte("[]"), | ||
| // Larger than the gzip reader's read buffer, so the | ||
| // reader stops before consuming all of the chunk data. | ||
| "chunk": make([]byte, 10*chunkSize), | ||
| }, | ||
| } | ||
| _, err := secretInterface.Create(context.Background(), corruptIndex, metav1.CreateOptions{}) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| for range 5 { | ||
| _, err := chunkedDriver.Get(corruptIndex.Name) | ||
| Expect(err).To(MatchError(ContainSubstring("failed to create gzip reader"))) | ||
| } | ||
| Eventually(countDecodeReleaseGoroutines).Should(BeZero()) | ||
| }) | ||
| }) | ||
|
|
||
| var _ = Describe("Update", func() { | ||
|
|
@@ -327,6 +349,17 @@ func verifySecrets(secretInterface clientcorev1.SecretInterface, expected int) { | |
| Expect(actualExtraChunkNames).To(ConsistOf(expectedExtraChunkNames)) | ||
| } | ||
|
|
||
| func countDecodeReleaseGoroutines() int { | ||
| buf := make([]byte, 1<<20) | ||
| for { | ||
| n := runtime.Stack(buf, true) | ||
| if n < len(buf) { | ||
| return strings.Count(string(buf[:n]), "(*chunkedSecrets).decodeRelease.func") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice way to make sure the fix worked, but I'm afraid it will be fragile. A change to the way stack is formatted, or changing the name of the type or I cannot think of a better way to do this, though. So we could either keep it and accept the above, or drop the test before merging given it's fulfilled its primary purpose. |
||
| } | ||
| buf = make([]byte, 2*len(buf)) | ||
| } | ||
| } | ||
|
|
||
| func releaseKey(rel *release.Release) string { | ||
| return fmt.Sprintf("%s.v%d", rel.Name, rel.Version) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd try to keep uses of
prtogether, and put it after the followinggo func(), right before thegzip.NewReader(pr)call below.