Repository navigation
internal/gzip: fix goroutine leak in ReadCloserLevel - #2347
Merged
Merged
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2347 +/- ##
==========================================
- Coverage 57.03% 57.03% -0.01%
==========================================
Files 166 166
Lines 11442 11441 -1
==========================================
- Hits 6526 6525 -1
Misses 4140 4140
Partials 776 776 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Subserial
reviewed
Jun 16, 2026
Move defer r.Close() and defer pw.Close() to the top of the goroutine so they execute regardless of which error path exits the function. Previously, r.Close() was only called inside the io.Copy error path and the happy-path end, leaving it unclosed when gw.Close() or bw.Flush() failed. When r wraps a limitedReadCloser (used by the pullLimiter introduced in google#2271), failing to close r permanently leaks the limiter token slot. Under layout.WriteImage (used by kaniko for build-stage caching), this eventually deadlocks because all slots are occupied. Also add defer gw.Close() after gw creation so the gzip writer is always properly finalized. Fixes google#2342 Signed-off-by: Aaron <[email protected]>
amarkdotdev
force-pushed
the
fix/gzip-goroutine-leak
branch
from
June 17, 2026 04:06
3ad742a to
7ad33fb
Compare
Subserial
approved these changes
Jun 17, 2026
social4hyq
pushed a commit
to social4hyq/homebrew-core
that referenced
this pull request
Sep 20, 2026
crane 0.21.7 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## What's Changed * tarball: return error instead of panicking on missing rootfs.diff_ids by @iahsanGill in google/go-containerregistry#2304 * gcrane: honor --platform flag in copy by @iahsanGill in google/go-containerregistry#2307 * mutate: verify layer digests in Extract and Time by @momenashrafff in google/go-containerregistry#2303 * tarball: close layer readers during Write by @nandbhat in google/go-containerregistry#2308 * build(deps): bump the actions group across 1 directory with 2 updates by @dependabot[bot] in google/go-containerregistry#2311 * build(deps): bump github.com/docker/cli from 29.4.3+incompatible to 29.5.2+incompatible in the go-deps group across 1 directory by @dependabot[bot] in google/go-containerregistry#2312 * BUGFIX: Fail with error when read exceeds maximum by @inteon in google/go-containerregistry#2328 * build(deps): bump the actions group across 1 directory with 2 updates by @dependabot[bot] in google/go-containerregistry#2327 * fix(name): anchor loopback registry detection by @rohan-patnaik in google/go-containerregistry#2314 * Reject symlinks in OCI layout blobs by @mosskappa in google/go-containerregistry#2306 * fix(crane): avoid creating export tar on pull failure by @Haihan-Jiang in google/go-containerregistry#2318 * feat(kubernetes): allow ignoring pull secrets by @rohan-patnaik in google/go-containerregistry#2315 * fix(name): preserve localhost registry references by @rohan-patnaik in google/go-containerregistry#2316 * pkg/registry: export ErrNotFound by @malt3 in google/go-containerregistry#2176 * pkg/registry: export RedirectError by @malt3 in google/go-containerregistry#2177 * build(deps): bump the go-deps group across 1 directory with 2 updates by @dependabot[bot] in google/go-containerregistry#2343 * build(deps): bump the actions group across 1 directory with 2 updates by @dependabot[bot] in google/go-containerregistry#2344 * fix: prevent SSRF in google.List() pagination by @tufstraka in google/go-containerregistry#2332 * internal/gzip: fix goroutine leak in ReadCloserLevel by @amarkdotdev in google/go-containerregistry#2347 * fix(transport): apply refreshed bearer token after cross-host redirect by @64johnlee in google/go-containerregistry#2337 * build(deps): bump the go-deps group across 3 directories with 4 updates by @dependabot[bot] in google/go-containerregistry#2348 * fix(tarball): normalize paths when matching files by @bstoll in google/go-containerregistry#2334 * transport: do not re-attach bearer token after cross-host redirect by @evilgensec in google/go-containerregistry#2349 * Bump CI go version to 1.26.4 by @Subserial in google/go-containerregistry#2350 ## New Contributors * @momenashrafff made their first contribution in google/go-containerregistry#2303 * @nandbhat made their first contribution in google/go-containerregistry#2308 * @inteon made their first contribution in google/go-containerregistry#2328 * @rohan-patnaik made their first contribution in google/go-containerregistry#2314 * @mosskappa made their first contribution in google/go-containerregistry#2306 * @Haihan-Jiang made their first contribution in google/go-containerregistry#2318 * @tufstraka made their first contribution in google/go-containerregistry#2332 * @amarkdotdev made their first contribution in google/go-containerregistry#2347 * @64johnlee made their first contribution in google/go-containerregistry#2337 * @bstoll made their first contribution in google/go-containerregistry#2334 **Full Changelog**: https://github.com/google/go-containerregistry/compare/v0.21.6...v0.21.7</pre> <p>View the full release notes at <a href="https://github.com/google/go-containerregistry/releases/tag/v0.21.7">https://github.com/google/go-containerregistry/releases/tag/v0.21.7</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!11861
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ReadCloserLevelstarts a goroutine that holdsr io.ReadCloser. In several error paths (gw.Close(),bw.Flush()), the goroutine callspw.CloseWithError(err)without ever callingr.Close(). Whenrwraps alimitedReadCloser(pullLimiter from #2271), the token slot is permanently leaked, eventually deadlocking underlayout.WriteImage.Fix
Move
defer r.Close()anddefer pw.Close()to the top of the goroutine (resolving the existingTODO(go1.14)comment). Adddefer gw.Close()after creation. This ensures resources are released on every exit path.Testing
go build ./internal/gzip/andgo test ./internal/gzip/pass.Fixes #2342