Skip to content

fix(runregistry): retry record removal on Windows sharing violations - #5089

Merged
trungutt merged 1 commit into
docker:mainfrom
trungutt:fix/runregistry-windows-remove-retry
Dec 1, 2026
Merged

trungutt merged 1 commit into
docker:mainfrom
trungutt:fix/runregistry-windows-remove-retry

Conversation

@trungutt

@trungutt trungutt commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

TestStartSessionCoordinatorListenUsesIsolatedRegistry keeps failing on the Windows runner with "cancelling the run must remove the discovery record", even on PRs that don't touch this code (e.g. #5088).

The problem

When a run with a control plane shuts down, it deletes a small record file that tells other tools "a run is live at this address." That delete is tried only once, and if it fails, nothing notices.

On Linux and macOS, you can delete a file even while someone else is reading it. Windows refuses: if any other program has the file open at that moment, the delete fails. Two things often have the file open:

  • the test itself, which keeps checking the folder to see whether the record is gone yet;
  • Windows Defender, which scans new files.

If the single delete attempt lands at the wrong moment, it fails silently. The record then never goes away, because the cleanup that runs while reading the folder only removes records of processes that have died, and this process is still running. The test waits 30 seconds for something that will never happen, then fails.

The same can happen outside tests: any tool listing runs while one shuts down can leave behind a record pointing at a dead address.

Why the earlier fix didn't work

e10d488 assumed the delete was just slow on Windows and raised the wait from 5 to 30 seconds. But the delete isn't slow, it simply never happens again. Waiting longer changes nothing.

The fix

If the delete fails because the file is busy on Windows, wait a moment and try again. Waits start at 10ms and double each time, up to 250ms, for at most 5 seconds. Reads and scans take milliseconds, so a retry quickly succeeds. If it still fails after 5 seconds, a warning is logged instead of being silently ignored. Linux and macOS behave exactly as before.

The new Windows-only test holds the record file open while the cleanup runs, checks the cleanup keeps waiting instead of giving up, then releases the file and checks the record gets deleted. Without the fix, it fails every time, not just occasionally.

On Windows, DeleteFile fails while any handle on the record is open without
FILE_SHARE_DELETE: a concurrent List (os.ReadFile) or an AV scanner. The
cleanup tried once and ignored the error, and List never prunes a record
whose pid is still alive, so the record stayed until the process exited.

This is what TestStartSessionCoordinatorListenUsesIsolatedRegistry keeps
hitting on the Windows runner: the test polls List while the cleanup runs.
Widening its wait to 30s (e10d488) could not help, since the removal is
never retried.

Retry transient removal failures with a bounded backoff.

Signed-off-by: Trung Nguyen <trung.nguyen@docker.com>
@aheritier aheritier added area/registry OCI registry, agent sharing, push/pull kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Dec 1, 2026
@trungutt
trungutt marked this pull request as ready for review December 1, 2026 15:10
@trungutt
trungutt requested a review from a team as a code owner December 1, 2026 15:10

@aheritier aheritier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, no issues. Thanks for adding a Windows regression test that holds the file open during cleanup.

@trungutt
trungutt added this pull request to the merge queue Dec 1, 2026
Merged via the queue into docker:main with commit ddd3a56 Dec 1, 2026
17 checks passed
@trungutt
trungutt deleted the fix/runregistry-windows-remove-retry branch December 1, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/registry OCI registry, agent sharing, push/pull kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants