Skip to content

fix: make the TTY progress manager safe against concurrent and repeated Close - #2287

Merged
TerryHowe merged 1 commit into
oras-project:mainfrom
wleeaf:fix-progress-manager-close-race
Oct 24, 2026
Merged

TerryHowe merged 1 commit into
oras-project:mainfrom
wleeaf:fix-progress-manager-close-race

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Track and Close in cmd/oras/internal/display/status/progress/manager.go only checked closed(), which becomes true after rendering has stopped. A Track that ran while Close was in progress could call updating.Go after Close had already waited on the WaitGroup. Its status was then neither drained nor rendered before Close returned. Two concurrent Close calls could also both close renderDone and panic.

This follows the plan in the issue:

  • Add a closing flag guarded by m.lock.
  • Close checks and sets it under the lock, and returns errManagerStopped if it was already set. This also fixes the double-Close panic.
  • Track still calls render() first, because render takes the read lock. It then checks closing under the write lock and calls updating.Go while still holding the lock, so every successful Track is waited for by Close.

The eager render() in Track is left unchanged, as the issue suggests.

Tests (run with -race):

  • Test_manager_Track_concurrentClose: over 100 rounds, a Track runs concurrently with Close. Each Track either returns errManagerStopped, or its status is tracked and drained before Close returns.
  • Test_manager_Close_concurrent: over 100 rounds, two concurrent Close calls do not panic, and exactly one returns errManagerStopped.

Without the fix, both tests failed in 200 of 200 runs (close of closed channel / tracked status is not drained when manager.Close() returns). With the fix, they passed 1000 of 1000 runs with -race.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2279

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

…ed Close

Track and Close only checked whether rendering had already stopped, so a
Track that ran while Close was in progress could add to the updating
WaitGroup after Close had waited on it, and its status was neither
drained nor rendered before Close returned. Two concurrent Close calls
could also both close renderDone and panic.

Add a closing flag guarded by the manager lock. Close checks and sets
it, returning errManagerStopped if it was already set. Track checks it
under the write lock and starts updating while still holding the lock.

Fixes #2279

Signed-off-by: Wleeaf <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 24, 2026 05:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.92%. Comparing base (9218890) to head (293422a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2287      +/-   ##
==========================================
+ Coverage   60.78%   60.92%   +0.13%     
==========================================
  Files         140      140              
  Lines        6092     6098       +6     
==========================================
+ Hits         3703     3715      +12     
+ Misses       2167     2163       -4     
+ Partials      222      220       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@TerryHowe
TerryHowe merged commit 3d087a2 into oras-project:main Oct 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants