Repository navigation
Conversation
messenger.Close() closed the update channel, but the tracked reader that feeds Update/Fail can outlive the call that closes the tracker. The most common case is the net/http transport write loop, which keeps reading the request body after the round trip returns: PushReference closes the tracker via defer r.StopTracker(), then a late read hits an error, calls readTracker.Fail, and sends on the now-closed channel, panicking the process. Stop closing the update channel. The messenger now owns a done channel that Close closes, every blocking send selects on it, and the drain goroutine uses it to stop after applying whatever is still buffered. Late updates are dropped instead of panicking, and Close stays idempotent via sync.Once. Selecting on done while still closing the update channel would not have been enough: select picks a ready send case before the send happens, so a close in that window still panics. Signed-off-by: harshasiddartha <[email protected]>
siddartha018
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
August 5, 2026 21:31
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2126 +/- ##
==========================================
+ Coverage 87.36% 87.40% +0.04%
==========================================
Files 139 139
Lines 5526 5544 +18
==========================================
+ Hits 4828 4846 +18
Misses 419 419
Partials 279 279 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
Thanks! |
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.
What this PR does / why we need it:
oras copycan panic withsend on closed channelin the progress display.The race, precisely:
messenger.Close()didm.update <- updateStatusEndTime(); close(m.update). It is called fromReader.StopTracker(), which runs viadefer r.StopTracker()inreferenceGraphTarget.PushReference/Push— i.e. as soon as the push call returns.net/http'spersistConn.writeLoopgoroutine keeps reading it after the round trip has returned. When one of those late reads returns a non-EOF error,readTracker.Readcallstracker.Fail(err), which was an unguardedm.update <- updateStatusError(err).PushReference) and the sending goroutine (net/httpwriteLoop) are unsynchronized, and a send can land after the close. That is exactly the reported stack:writeLoop → doBodyCopy → readTracker.Read → messenger.Fail.writeTracker.Writehas the sameFailpath.The existing
closed boolonly short-circuited a secondClose(); it was unsynchronized and did not guardUpdate/Fail.The fix: the messenger no longer closes the update channel at all. It owns a
donechannel thatClosecloses (once, viasync.Once), every blocking send selects ondone, and the drain goroutine inmanager.newTrackernow stops ondoneafter applying whatever is still buffered. A lateUpdate/Failtherefore takes thedonebranch and drops the update instead of panicking.Closesends the end-time update before closingdone, so the final status is never lost.Note on the approach: adding a
selectondonewhile still closing the update channel would not have fixed it.selectcommits to a ready send case and then performs the send, so a concurrentclosein that window still panics. Not closing the channel is what actually serializes the two goroutines — the only cross-goroutine transition left isclose(done), and a closeddoneis permanently ready, so senders can neither panic nor block. A mutex held across the blocking send was rejected as it couples sender liveness to the drain goroutine.Reproduced before the fix with
go test -race(drain goroutine + a goroutine callingFailwhileCloseruns):Test_messenger_Close_concurrentUpdateis the regression test for it; it fails if the channel close is put back.Verified:
go build ./...,go vet ./...,go test -race ./...(all packages pass),golangci-lint run ./...(0 issues).Which issue(s) this PR fixes:
Fixes #2125
Please check the following list: