Skip to content

bug: race between Track and Close in the TTY progress manager #2279

Closed

Description

@TerryHowe

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 WaitGroup after Wait, 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 bool guarded by m.lock.
    • In Track, check it under the write lock and call updating.Go while still holding the lock. Call the existing render() before taking the lock, because render takes RLock and RWMutex is not reentrant.
    • In Close, check and set it under the lock, and return errManagerStopped if it was already set. This also fixes the double-Close panic.
  • Add -race tests:
    • Track concurrently with Close: each Track either succeeds and its drain finishes before Close returns, or it returns errManagerStopped.
    • Two concurrent Close calls: no panic, and exactly one returns errManagerStopped.

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

  1. added
    bug
    help wanted
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions