Skip to content

[Breaking change]: Socket.SendFile/EndSendFile/SendFileAsync throws NotSupportedException for connectionless sockets #37544

@antonfirsov

Description

@antonfirsov

Description

The previous ad-hoc behavior of the SendFile method family for connectionless (eg. UDP) sockets has been harmonized to throw NotSupportedException on all platforms.

Version

.NET 8 RC 1

Previous behavior

Assuming a connectionless (eg. UDP) Socket:

  • SendFile throws SocketException on Windows, and no exception on Unix-like platforms
  • Awaiting a ValueTask returned from SendFileAsync throws SocketException asynchronously on all platforms
  • Calling EndSendFile on an IAsyncResult returned from BeginSendFile throws SocketException on all platforms

New behavior

Assuming a connectionless (eg. UDP) Socket:

  • SendFile throws NotSupportedException on all platforms
  • Awaiting a ValueTask returned from SendFileAsync throws NotSupportedException asynchronously on all platforms
  • Calling EndSendFile on an IAsyncResult returned from BeginSendFile throws NotSupportedException on all platforms

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

Given that SendFile is typically used with large amounts of data, it doesn't really make sense to use it with connectionless sockets. The previous behavior was ad-hoc, throwing SocketException on some platforms, while succeeding on others with unclear outcome.

See dotnet/runtime#47472.

Recommended action

SendFile should not be attempted for connectionless sockets.

Feature area

Networking

Affected APIs

Socket.SendFile, Socket.SendFileAsync, Socket.EndSendFile (all overloadss).


Associated WorkItem - 177290

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 8Work items for the .NET 8 release📌 seQUESTeredIdentifies that an issue has been imported into Quest.breaking-changeIndicates a .NET Core breaking change

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions