Repository navigation
Description
What is the problem?
There is a race between Track and Close in cmd/oras/internal/display/status/progress/manager.go:
func (m *manager) Track(desc ocispec.Descriptor) (progress.Tracker, error) {
if m.closed() { // checks renderClosed only
return nil, errManagerStopped
}
m.render()
...
return m.newTracker(s), nil // m.updating.Go(...)
}
func (m *manager) Close() error {
if m.closed() {
return errManagerStopped
}
m.updating.Wait() // (1)
close(m.renderDone) // (2)
<-m.renderClosed // (3)
}closed() only becomes true after step (3). A Track call that runs between (1) and (3) passes the check and calls m.updating.Go after Wait has returned. Two things go wrong:
- It reuses the
WaitGroupafterWait, which is a documented misuse: "calls with a positive delta that occur when the counter is zero must happen before a Wait". - The status is appended after the final render, so its progress line is never shown, and its drain goroutine can outlive
Close.
The same check-then-act gap lets two concurrent Close calls both pass closed() and both close(m.renderDone), which panics.
#2125 (send on closed channel in the messenger) fixed a related shutdown race. This window is still present.
Is it reachable today?
Not through the current CLI commands. track.Report (status/track/target.go) runs from oras-go copy callbacks (OnCopySkipped, PostCopy), and oras-go's copyGraph waits for every callback before returning, even on error (syncutil.Go → eg.Wait()). StopTracking / Close is deferred until after the copy returns (e.g. cmd/oras/root/cp.go), so the calls are ordered.
This is a hole in the manager's API contract, not a bug users can hit. It is worth hardening so a future caller, or a test, cannot trip it.
Proposed fix
- Add a
closing boolguarded bym.lock.- In
Track, check it under the write lock and callupdating.Gowhile still holding the lock. Call the existingrender()before taking the lock, becauserendertakesRLockandRWMutexis not reentrant. - In
Close, check and set it under the lock, and returnerrManagerStoppedif it was already set. This also fixes the double-Closepanic.
- In
- Add
-racetests:Trackconcurrently withClose: eachTrackeither succeeds and its drain finishes beforeClosereturns, or it returnserrManagerStopped.- Two concurrent
Closecalls: no panic, and exactly one returnserrManagerStopped.
Affected scope: one file plus tests, in an internal package with no public API.
Out of scope: eager render() in Track
Track does a synchronous render() on every call, and Report runs Track+Update+Close per skipped node. That render is not free to drop: it paints existing rows at their current positions before NewRow() scrolls the view, so removing it risks half-painted or duplicated rows for up to one frame (200 ms). Rendering only on height change does not help, because the height changes on every Track. The cost is also bounded, since render culls to the last height/2 statuses, so each call is O(terminal height), not O(n).
If this is worth pursuing, do it in a separate change backed by a benchmark (e.g. Report over ~10k nodes).
oras-go v3 note
This is CLI-only code and is unchanged on the v3 migration branch (#2002).
Activity