Skip to content

Re-enable the WhenDiskIsFullTheErrorMessageContainsAllDetails test on Windows#125707

Merged
adamsitnik merged 3 commits intomainfrom
copilot/fix-file-stream-preallocation-error
Mar 18, 2026
Merged

Re-enable the WhenDiskIsFullTheErrorMessageContainsAllDetails test on Windows#125707
adamsitnik merged 3 commits intomainfrom
copilot/fix-file-stream-preallocation-error

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

Description

On Windows, SetFileInformationByHandle returns ERROR_INVALID_PARAMETER (87) when the requested preallocation size exceeds the NTFS maximum file size for the volume's cluster size. The Preallocate method only checked for ERROR_DISK_FULL and ERROR_FILE_TOO_LARGE, so oversized hints silently no-oped instead of throwing IOException.

The fix (handling ERROR_INVALID_PARAMETER in SafeFileHandle.Preallocate) was already applied; this PR re-enables the suppressed test and updates the stale comment:

  • ctor_options.cs: Remove [ActiveIssue("…/92624", TestPlatforms.Windows)] from WhenDiskIsFullTheErrorMessageContainsAllDetails — test now runs on Windows and validates that a 1 EiB preallocation throws IOException containing the path and size, and does not leave the file on disk.
  • SafeFileHandle.Windows.cs: Update comment on the error-code guard to accurately describe that ERROR_INVALID_PARAMETER covers NTFS rejecting allocation sizes that exceed the volume's per-cluster-size file-size limit.

Changes

  • src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
  • src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_options.cs
Original prompt

This section details on the original issue you should resolve

<issue_title>new FileStream with too-large preallocation hint does not throw on Windows</issue_title>
<issue_description>This test assumes creating a 1TB file will fail -- this is why the first run test fails here, because I have 1.5TB free. edit: turns out it fails anyway on Windows

Note the 2nd flavor of the test passes here -- perhaps because the first file wasn't deleted (?) but I would expect dispose to have happened between them and cleaned up the test directory. edit: it's because the finalizer hadn't run before dispose.

      <test name="System.IO.Tests.FileStream_ctor_options.WhenDiskIsFullTheErrorMessageContainsAllDetails(mode: Create)" type="System.IO.Tests.FileStream_ctor_options" method="WhenDiskIsFullTheErrorMessageContainsAllDetails" time="0.0389214" result="Fail">
        <traits>
          <trait name="category" value="outerloop" />
        </traits>
        <failure exception-type="Xunit.Sdk.ThrowsException">
          <message><![CDATA[Assert.Throws() Failure\r\nExpected: typeof(System.IO.IOException)\r\nActual:   (No exception was thrown)]]></message>
          <stack-trace><![CDATA[   at System.IO.Tests.FileStream_ctor_options.WhenDiskIsFullTheErrorMessageContainsAllDetails(FileMode mode) in C:\git\runtime\src\libraries\System.IO.FileSystem\tests\FileStream\ctor_options.cs:line 169
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr) in C:\git\runtime\src\libraries\System.Private.CoreLib\src\System\Reflection\MethodBaseInvoker.cs:line 157]]></stack-trace>
        </failure>
      </test>
      <test name="System.IO.Tests.FileStream_ctor_options.WhenDiskIsFullTheErrorMessageContainsAllDetails(mode: CreateNew)" type="System.IO.Tests.FileStream_ctor_options" method="WhenDiskIsFullTheErrorMessageContainsAllDetails" time="0.0028693" result="Pass">
        <traits>
          <trait name="category" value="outerloop" />
        </traits>
      </test>

It should try to create a 100TB file or something, and we can meet back here in 2028. 😄 </issue_description>

Comments on the Issue (you are @copilot in this section)

@ Tagging subscribers to this area: @dotnet/area-system-io See info in [area-owners.md](https://github.com/dotnet/runtime/blob/main/docs/area-owners.md) if you want to be subscribed.
Issue Details

This test assumes creating a 1TB file will fail -- this is why the first run test fails here, because I have 1.5TB free.

Note the 2nd flavor of the test passes here -- perhaps because the first file wasn't deleted (?) but I would expect dispose to have happened between them and cleaned up the test directory.

      <test name="System.IO.Tests.FileStream_ctor_options.WhenDiskIsFullTheErrorMessageContainsAllDetails(mode: Create)" type="System.IO.Tests.FileStream_ctor_options" method="WhenDiskIsFullTheErrorMessageContainsAllDetails" time="0.0389214" result="Fail">
        <traits>
          <trait name="category" value="outerloop" />
        </traits>
        <failure exception-type="Xunit.Sdk.ThrowsException">
          <message><![CDATA[Assert.Throws() Failure\r\nExpected: typeof(System.IO.IOException)\r\nActual:   (No exception was thrown)]]></message>
          <stack-trace><![CDATA[   at System.IO.Tests.FileStream_ctor_options.WhenDiskIsFullTheErrorMessageContainsAllDetails(FileMode mode) in C:\git\runtime\src\libraries\System.IO.FileSystem\tests\FileStream\ctor_options.cs:line 169
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr) in C:\git\runtime\src\libraries\System.Private.CoreLib\src\System\Reflection\MethodBaseInvoker.cs:line 157]]></stack-trace>
        </failure>
      </test>
      <test name="System.IO.Tests.FileStream_ctor_options.WhenDiskIsFullTheErrorMessageContainsAllDetails(mode: CreateNew)" type="System.IO.Tests.FileStream_ctor_options" method="WhenDiskIsFullTheErrorMessageContainsAllDetails" time="0.0028693" result="Pass">
        <traits>
          <trait name="category" value="outerloop" />
        </traits>
      </test>

It should try to create a 100TB file or something, and we can meet back here in 2028. 😄

Author: danmoseley
Assignees: -
Labels:

area-System.IO

Milestone: -

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix new FileStream preallocation hint error on Windows Fix FileStream preallocation silently ignoring ERROR_INVALID_PARAMETER (87) on Windows Mar 18, 2026
Copilot AI requested a review from danmoseley March 18, 2026 03:51
@danmoseley danmoseley requested review from Copilot and removed request for danmoseley March 18, 2026 05:00
Copy link
Contributor

Copilot AI left a comment

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 re-enables a Windows FileStream preallocation test and clarifies the rationale behind Windows preallocation failure handling in SafeFileHandle.

Changes:

  • Removed a Windows-only [ActiveIssue] suppression for the “disk full” preallocation error-message test.
  • Updated comments in Windows SafeFileHandle.Preallocate to better describe when SetFileInformationByHandle can fail for oversized allocations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_options.cs Removes Windows test suppression so the preallocation error-message test runs again on Windows.
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs Refines explanatory comments for preallocation failure modes on Windows (no functional logic change in this diff).

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@adamsitnik adamsitnik marked this pull request as ready for review March 18, 2026 10:59
Copilot AI review requested due to automatic review settings March 18, 2026 10:59
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, but I am going to update the title to make it clear that it's not fixing the bug but just enabling a test.

@adamsitnik adamsitnik changed the title Fix FileStream preallocation silently ignoring ERROR_INVALID_PARAMETER (87) on Windows Re-enable the WhenDiskIsFullTheErrorMessageContainsAllDetails test on Windows Mar 18, 2026
@adamsitnik adamsitnik added the test-enhancement Improvements of test source code label Mar 18, 2026
@adamsitnik adamsitnik added this to the 11.0.0 milestone Mar 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enables a previously skipped FileStream preallocation error-message test on Windows by updating Windows preallocation error handling to treat additional filesystem-limit failures as “disk full / file too large” conditions.

Changes:

  • Unskips WhenDiskIsFullTheErrorMessageContainsAllDetails on Windows.
  • Treats ERROR_INVALID_PARAMETER from SetFileInformationByHandle(FileAllocationInfo) as a “file too large” preallocation failure (delete created file + throw IOException), aligning behavior with the test’s expectations.

Reviewed changes

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

File Description
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_options.cs Removes the Windows ActiveIssue skip so the disk-full/file-too-large message test runs on Windows and Linux (still excluded on macOS).
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs Expands the set of Win32 errors that trigger the “preallocation failed” exception path to include ERROR_INVALID_PARAMETER, mapping it to “file too large”.

You can also share your feedback on Copilot code review. Take the survey.

@adamsitnik adamsitnik enabled auto-merge (squash) March 18, 2026 11:06
@adamsitnik adamsitnik merged commit fdbedda into main Mar 18, 2026
150 of 155 checks passed
@adamsitnik adamsitnik deleted the copilot/fix-file-stream-preallocation-error branch March 18, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO test-enhancement Improvements of test source code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new FileStream with too-large preallocation hint does not throw on Windows

5 participants