Skip to content

content: handle sharing violations on Windows - #13329

Merged
mxpv merged 1 commit into
containerd:mainfrom
ayush-panta:fix-flaky-windows-test-content-client
Jun 25, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
ayush-panta:fix-flaky-windows-test-content-client

Conversation

@ayush-panta

Copy link
Copy Markdown
Contributor

Problem

Issue #11044 highlights that TestContentClient/CommitErrorState flakes on Windows CI with sharing violations during cleanup:

Cleanup failed: failed to abort c1-commiterror-state: unlinkat ...\updatedat.tmp:
The process cannot access the file because it is being used by another process.

Root cause

I believe the root cause is a race between the gRPC server-side defer wr.Close() (which writes updatedat.tmp via writeToCompletion) and the client-side cleanup calling Abort (which runs os.RemoveAll on the ingest directory). On Unix this doesn't matter since you can unlink files with open handles. On Windows, the OS can hold handles briefly after Close() returns, so deletes and reads hit a sharing violation.

While investigating, I found the same race also affects readFileTimestamp in status(), where the updatedat file can't be read while the handle is still held. This wasn't called out in the issue, but I ran into it while testing, so I fixed it as well.

Fix

Adds removePath and readFileWithRetry as platform-specific helpers in plugins/content/local/. On Windows they retry with linear backoff (5 attempts, 100-500ms). On other platforms they pass through directly. Same pattern as ensureRemoveAll in internal/cri/server/helpers_linux.go, which retries on EBUSY for mount races.

Test results

I ran TestContentClient/CommitErrorState 500 times on a Windows Server 2022 EC2 instance (t3.large). The race reproduces naturally but infrequently (~11% with mainline containerd v2.3 on this instance type, could vary based on instance) so I used a large number of runs to get a clear signal.

The "before" run uses mainline at 2976f38cc. The "after" commit hash (d0911796a) differs from the final PR commit because I amended after testing for a few edits.

The three failure types are all the same underlying race hitting different operations:

  • abort-unlinkat: Abort calls os.RemoveAll, fails to delete a file in the ingest directory (the original error)
  • dir-not-empty: Abort calls os.RemoveAll, can't remove the directory because a held file blocks child deletion
  • read-updatedat: status() calls readFileTimestamp, can't open updatedat while the handle is still held
=== BEFORE FIX === (2976f38cc, mainline v2.3.0)
PASS: 444  FAIL: 56  (11.2%)
  abort-unlinkat: 46
  read-updatedat: 10
  dir-not-empty:  8

=== AFTER FIX === (d0911796a)
PASS: 500  FAIL: 0
  abort-unlinkat: 0
  read-updatedat: 0
  dir-not-empty:  0

Fixes #11044

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.

Pull request overview

This PR reduces Windows CI flakes in the local content store by adding Windows-specific retry behavior around filesystem operations that can fail transiently due to sharing violations.

Changes:

  • Add Windows implementations of removePath (retrying os.RemoveAll) and readFileWithRetry (retrying os.ReadFile) with a small backoff.
  • Add non-Windows passthrough implementations of the same helpers.
  • Switch store.Abort and readFileTimestamp to use the new helpers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
plugins/content/local/store_windows.go Adds retrying wrappers for remove/read to mitigate transient Windows sharing violations.
plugins/content/local/store_other.go Adds non-Windows passthrough implementations to keep call sites platform-agnostic.
plugins/content/local/store.go Routes Abort cleanup and timestamp reads through the new helper functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/content/local/store_windows.go Resolved
Comment thread plugins/content/local/store_windows.go Resolved
@ayush-panta
ayush-panta force-pushed the fix-flaky-windows-test-content-client branch from 91d00a3 to 0bda8f9 Compare May 1, 2026 06:23
Copilot AI review requested due to automatic review settings May 1, 2026 06:24

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.

Pull request overview

Adds Windows-specific retry handling in the local content store to avoid transient sharing-violation failures when aborting ingests and reading timestamp state files.

Changes:

  • Introduces platform-specific helpers removePath and readFileWithRetry (Windows: retry with backoff; others: passthrough).
  • Updates store.Abort to use removePath instead of os.RemoveAll.
  • Updates readFileTimestamp to use readFileWithRetry instead of os.ReadFile.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
plugins/content/local/store_windows.go Adds Windows retry/backoff wrappers for RemoveAll and ReadFile to mitigate transient sharing violations.
plugins/content/local/store_other.go Adds non-Windows implementations of the new helper functions (direct passthrough).
plugins/content/local/store.go Switches ingest cleanup and timestamp reads to use the new helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/content/local/store_windows.go Resolved
Comment thread plugins/content/local/store_windows.go Resolved
@ayush-panta
ayush-panta marked this pull request as draft May 1, 2026 06:36
@ayush-panta
ayush-panta force-pushed the fix-flaky-windows-test-content-client branch from 0bda8f9 to 0a996a5 Compare May 1, 2026 06:58
@k8s-ci-robot k8s-ci-robot added size/L and removed size/M labels May 1, 2026
@ayush-panta
ayush-panta marked this pull request as ready for review May 1, 2026 07:46
Copilot AI review requested due to automatic review settings May 1, 2026 07:46

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.

Pull request overview

This PR addresses flaky Windows CI failures in the local content store by adding Windows-specific retries for file operations that can transiently fail due to sharing/lock violations.

Changes:

  • Add Windows retry helpers for RemoveAll and ReadFile to tolerate transient sharing violations.
  • Route ingest cleanup (Abort) through the retrying remove helper.
  • Route timestamp reads (readFileTimestamp) through the retrying read helper, preventing status/read flakes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
plugins/content/local/store_windows.go Adds retry logic for Windows sharing/lock-related failures in delete/read file operations.
plugins/content/local/store_other.go Provides non-Windows passthrough implementations for the new helper functions.
plugins/content/local/store.go Switches Abort cleanup and timestamp reads to use the new platform-specific helper wrappers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ayush-panta
ayush-panta force-pushed the fix-flaky-windows-test-content-client branch from 0a996a5 to f1fa777 Compare May 27, 2026 22:16
Copilot AI review requested due to automatic review settings May 28, 2026 20:42
@ayush-panta
ayush-panta force-pushed the fix-flaky-windows-test-content-client branch from f1fa777 to 6f92e34 Compare May 28, 2026 20:42

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread plugins/content/local/store_windows.go Resolved
Comment thread plugins/content/local/store_windows.go Resolved
Comment thread plugins/content/local/store_windows.go Resolved
@ayush-panta
ayush-panta force-pushed the fix-flaky-windows-test-content-client branch from 6f92e34 to 1b5a94b Compare May 28, 2026 23:07
Copilot AI review requested due to automatic review settings May 28, 2026 23:24
@ayush-panta
ayush-panta force-pushed the fix-flaky-windows-test-content-client branch from 1b5a94b to 3140c26 Compare May 28, 2026 23:24

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread plugins/content/local/store_windows.go Resolved
Comment thread plugins/content/local/store_windows.go Resolved
Comment thread plugins/content/local/store_windows.go Resolved
Comment thread plugins/content/local/store_windows.go Resolved
On Windows, os.RemoveAll and os.ReadFile can fail with a sharing
violation when a file handle has not been fully released by the OS.
Unlike Unix, Windows does not allow deleting or reading a file
while any handle is open, and handles may be held briefly after
Close returns. This causes a race between the gRPC server-side
writer Close (which writes updatedat.tmp) and both Abort (which
calls RemoveAll on the ingest directory) and status (which reads
the updatedat file), surfacing as a flaky
TestContentClient/CommitErrorState on Windows CI.

Add platform-specific removePath and readFileWithRetry helpers
that retry with incremental backoff on Windows. On non-Windows
platforms they pass through to os.RemoveAll and os.ReadFile
directly. This follows the same pattern as ensureRemoveAll in
the CRI server helpers, which retries on EBUSY for mount races
on Linux.

Signed-off-by: ayush-panta <[email protected]>
@samuelkarp samuelkarp moved this from Needs Triage to Needs Reviewers in Pull Request Review Jun 2, 2026
@github-project-automation github-project-automation Bot moved this from Needs Reviewers to Review In Progress in Pull Request Review Jun 25, 2026
@mxpv
mxpv added this pull request to the merge queue Jun 25, 2026
Merged via the queue into containerd:main with commit ef8a596 Jun 25, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 25, 2026
@ayush-panta
ayush-panta deleted the fix-flaky-windows-test-content-client branch June 25, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

TestContentClient/CommitErrorState occasionally fails on Windows

5 participants