Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified to throw NotSupportedException when SendFile() for connectionless sockets #87108

Merged
merged 5 commits into from
Aug 9, 2023
Merged

Unified to throw NotSupportedException when SendFile() for connectionless sockets #87108

merged 5 commits into from
Aug 9, 2023

Conversation

rhirano0715
Copy link
Contributor

The issue was that the Socket.SendFile() threw inconsistent exceptions when the platform was Windows and the protocol was UDP. The first call would throw a SocketException, while the second call would throw a NotSupportedException.

With this commit, SendFile() will consistently throw NotSupportException on all platforms when the protocol is UDP.

Fix #47472

…less sockets

The issue was that the Socket.SendFile() threw inconsistent exceptions when the platform was Windows and the protocol was UDP.
The first call would throw a SocketException, while the second call would throw a NotSupportedException.

With this commit, SendFile() will consistently throw NotSupportException on all platforms when the protocol is UDP.

Fix #47472
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jun 4, 2023
@ghost
Copy link

ghost commented Jun 4, 2023

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

The issue was that the Socket.SendFile() threw inconsistent exceptions when the platform was Windows and the protocol was UDP. The first call would throw a SocketException, while the second call would throw a NotSupportedException.

With this commit, SendFile() will consistently throw NotSupportException on all platforms when the protocol is UDP.

Fix #47472

Author: rhirano0715
Assignees: -
Labels:

area-System.Net.Sockets

Milestone: -

@rhirano0715
Copy link
Contributor Author

@dotnet-policy-service agree

@karelz
Copy link
Member

karelz commented Jul 3, 2023

@antonfirsov ping, can you please take a look?

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

Sorry for the long delay!

Comment on lines 2341 to 2344
if (_protocolType == ProtocolType.Udp)
{
throw new NotSupportedException(SR.net_notconnected);
}
Copy link
Member

Choose a reason for hiding this comment

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

Given that BeginSendFile calls into SendFileAsync, this check is redundant.

if (usePreAndPostbufferOverload)
{
ex = await Assert.ThrowsAsync<SocketException>(() => SendFileAsync(client, tempFile.Path, Array.Empty<byte>(), Array.Empty<byte>(), TransmitFileOptions.UseDefaultWorkerThread));
await Assert.ThrowsAsync<NotSupportedException>(() => SendFileAsync(client, tempFile.Path, Array.Empty<byte>(), Array.Empty<byte>(), TransmitFileOptions.UseDefaultWorkerThread));
Copy link
Member

Choose a reason for hiding this comment

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

This test case should not be [PlatformSpecific(TestPlatforms.Windows)] anymore.

Comment on lines 673 to 676
if (_protocolType == ProtocolType.Udp)
{
throw new NotSupportedException(SR.net_notconnected);
}
Copy link
Member

@antonfirsov antonfirsov Jul 4, 2023

Choose a reason for hiding this comment

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

Doesn't the check if (!IsConnectionOriented) do the job already? In #47472 I only tested the sync overload.

Comment on lines 1257 to 1260
if (_protocolType == ProtocolType.Udp)
{
throw new NotSupportedException(SR.net_notconnected);
}
Copy link
Member

Choose a reason for hiding this comment

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

The async variant checks for if (!IsConnectionOriented) while the sync version checks (!Connected). I think that - instead of limiting the error case explicitly to UDP - we should consolidate these checks, throwing in case of (!IsConnectionOriented || !Connected).

@karelz
Copy link
Member

karelz commented Jul 18, 2023

@rhirano0715 will you have time to look at the CR feedback from @antonfirsov please?

rhirano0715 and others added 3 commits July 19, 2023 18:06
…r `!Connected`.

Before:.

    Throws `NotSupportedException` on UDP.

After:

    Throws `NotSupportedException` if `!IsConnectionOriented` or `!Connected`.
@rhirano0715
Copy link
Contributor Author

@karelz @antonfirsov
I'm sorry for not being able to respond.
Thank you for your review.
I have committed the correction.

@antonfirsov antonfirsov added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Aug 4, 2023
@antonfirsov
Copy link
Member

/azp run runtime

@antonfirsov
Copy link
Member

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

LGTM, thanks, and sorry for the slow response. Started some extra CI runs just in case.

@MihaZupan
Copy link
Member

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MihaZupan MihaZupan merged commit 24f1513 into dotnet:main Aug 9, 2023
147 of 171 checks passed
@karelz karelz added this to the 8.0.0 milestone Aug 10, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 9, 2023
@antonfirsov antonfirsov removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Oct 17, 2023
@rhirano0715 rhirano0715 deleted the issue47472 branch December 6, 2023 08:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Sockets community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Socket.SendFile() should fail with a consistent exception for connectionless sockets
4 participants