Skip to content

fix: make MockFileStream flush tolerant of concurrent file deletion - #1614

Open
lee3Q wants to merge 2 commits into
TestableIO:mainfrom
lee3Q:lee3Q-patch-2
Open

lee3Q wants to merge 2 commits into
TestableIO:mainfrom
lee3Q:lee3Q-patch-2

Conversation

@lee3Q

@lee3Q lee3Q commented Dec 1, 2026

Copy link
Copy Markdown

Fixes #784

MockFileStream.InternalFlush checked FileExists(path) and then called GetFile(path). These are two separate lookups on the mock file system, so a file that was deleted between them left mockFileData null and mockFileData.Contents = data threw a NullReferenceException.

The file data is now fetched once with GetFile and checked for null. Without a concurrent delete the behavior is the same as before (FileExists and GetFile read the same dictionary), and a flush for a file that no longer exists is skipped as it was before.

Test: MockFileStream_Flush_WhenFileIsRemovedBeforeFetch_ShouldNotThrow. It uses a small IMockFileDataAccessor wrapper that removes the file right before the first GetFile call, so the interleaving is deterministic and does not depend on timing. It fails with a NullReferenceException in InternalFlush without the change and passes with it.

Checked locally on net11.0 (the whole TestingHelpers.Tests project passes with the change) and on net10.0 for the new test. net9.0, net8.0 and net472 were not run. dotnet format reports nothing in the changed lines.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 01:15

Copilot AI left a comment

Copy link
Copy Markdown

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. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@mergify

mergify Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

This branch has not been deployed

No deployments
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.

MockFileStream.InternalFlush is not thread-safe

2 participants