Skip to content

docs: Breaking change — SafeFileHandle.IsAsync and FileStream.IsAsync now reflect actual O_NONBLOCK state on Unix (.NET 11)#52888

Open
Copilot wants to merge 5 commits intomainfrom
copilot/fix-safe-file-handle-is-async
Open

docs: Breaking change — SafeFileHandle.IsAsync and FileStream.IsAsync now reflect actual O_NONBLOCK state on Unix (.NET 11)#52888
Copilot wants to merge 5 commits intomainfrom
copilot/fix-safe-file-handle-is-async

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

In .NET 11 Preview 3, SafeFileHandle.IsAsync and FileStream.IsAsync on Unix changed from always returning true for files opened with FileOptions.Asynchronous to accurately reflecting whether O_NONBLOCK is set on the file descriptor. Regular files now return false; only genuinely non-blocking fds (pipes, sockets) return true.

Changes

  • New article docs/core/compatibility/core-libraries/11/safefilehandle-isasync-unix.md covering:
    • SafeFileHandle.IsAsync / FileStream.IsAsync Unix behavior change
    • SendPacketsElement(FileStream, ...) no longer throws ArgumentException on non-Windows for non-async streams
    • Recommended actions for each impacted scenario
  • 11.md — added row under Core .NET libraries
  • toc.yml — added entry under .NET 11 > Core .NET libraries

Behavior at a glance

// Before (.NET 10): always true for FileOptions.Asynchronous on Unix
using SafeFileHandle h = File.OpenHandle("file.txt", options: FileOptions.Asynchronous);
Console.WriteLine(h.IsAsync); // true (misleading — no O_NONBLOCK on regular file)

// After (.NET 11): reflects actual fd state
SafeFileHandle.CreateAnonymousPipe(out var read, out var write, asyncRead: true, asyncWrite: false);
Console.WriteLine(read.IsAsync);  // true  (O_NONBLOCK set)
Console.WriteLine(write.IsAsync); // false (blocking)
// Regular file: false

Internal previews

📄 File 🔗 Preview link
docs/core/compatibility/11.md Breaking changes in .NET 11
docs/core/compatibility/core-libraries/11/safefilehandle-isasync-unix.md SafeFileHandle.IsAsync and FileStream.IsAsync accurately reflect non-blocking state on Unix
docs/core/compatibility/toc.yml docs/core/compatibility/toc

…change in .NET 11

Agent-Logs-Url: https://github.com/dotnet/docs/sessions/8ae53bcd-ed7a-4368-898a-433576b68e76

Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SafeFileHandle.IsAsync to reflect non-blocking state on Unix docs: Breaking change — SafeFileHandle.IsAsync and FileStream.IsAsync now reflect actual O_NONBLOCK state on Unix (.NET 11) Apr 7, 2026
Copilot AI requested a review from gewarren April 7, 2026 17:24
Corrected the behavior of SafeFileHandle.IsAsync on Unix to accurately reflect the non-blocking state of file descriptors. Updated documentation to clarify the changes and their implications.
@gewarren gewarren marked this pull request as ready for review April 7, 2026 20:19
@gewarren gewarren requested a review from a team as a code owner April 7, 2026 20:19
@gewarren gewarren requested review from adamsitnik and Copilot April 7, 2026 20:19
Copy link
Copy Markdown
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

Adds a new .NET 11 breaking change article documenting updated Unix semantics for SafeFileHandle.IsAsync and FileStream.IsAsync, and wires the article into the .NET compatibility index and TOC.

Changes:

  • Adds a new breaking change article describing the Unix IsAsync behavior update (and related SendPacketsElement behavior on non-Windows).
  • Updates the .NET 11 breaking changes index to include the new entry.
  • Updates the compatibility TOC to surface the new article under .NET 11 > Core .NET libraries.

Reviewed changes

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

File Description
docs/core/compatibility/core-libraries/11/safefilehandle-isasync-unix.md New breaking change article describing the updated Unix IsAsync behavior and recommended actions.
docs/core/compatibility/11.md Adds the new breaking change link to the .NET 11 index table.
docs/core/compatibility/toc.yml Adds a TOC entry so the new article appears in navigation.

Comment on lines +16 to +30
## Previous behavior

Previously, `SafeFileHandle.IsAsync` always returned `true` on Unix for regular files opened with `FileOptions.Asynchronous`, regardless of whether the underlying file descriptor had the `O_NONBLOCK` flag set.

```csharp
using Microsoft.Win32.SafeHandles;

// On Unix, IsAsync was true for regular files opened with FileOptions.Asynchronous,
// even though the file descriptor had no O_NONBLOCK set.
using SafeFileHandle handle = File.OpenHandle("myfile.txt", options: FileOptions.Asynchronous);
Console.WriteLine(handle.IsAsync); // true (misleading; no O_NONBLOCK on regular file)
```

On non-Windows platforms, constructing a `SendPacketsElement` with a non-async `FileStream` threw an `ArgumentException`.

Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The "Reason for change" section says SafeFileHandle.IsAsync previously reported false for genuinely non-blocking file descriptors (pipes/sockets with O_NONBLOCK), but the "Previous behavior" section only describes the regular-file scenario. Add a sentence in "Previous behavior" clarifying the pipe/socket case (and that the value was based on the open options rather than actual O_NONBLOCK) so the narrative doesn’t read as contradictory.

Copilot uses AI. Check for mistakes.
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 apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 2a1f4e0. The "Previous behavior" section now explicitly describes both scenarios: regular files returning true despite no O_NONBLOCK (values based on open options), and genuinely non-blocking pipes/sockets incorrectly returning false.

Copilot AI requested a review from gewarren April 7, 2026 20:29
Clarified the behavior of SafeFileHandle.IsAsync on Unix regarding asynchronous and non-blocking file descriptors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Breaking change]: SafeFileHandle.IsAsync now accurately reflects non-blocking state on Unix

3 participants