Ensure LocalEndPoint being updated in SendToAsync(SocketAsyncEventArgs)#808
Ensure LocalEndPoint being updated in SendToAsync(SocketAsyncEventArgs)#808antonfirsov merged 11 commits intomasterfrom
Conversation
| if (_rightEndPoint == null) | ||
| { | ||
| _rightEndPoint = endPointSnapshot; | ||
| } |
There was a problem hiding this comment.
I was not sure at which point should this happen. BeginSendTo assigns it before doing the actual WSA P/Invoke, I tried to follow that approach.
There was a problem hiding this comment.
Nit: for future reference, this can now be written as:
_rightEndPoint ??= endPointSnapshot;| Task.Run(() => s.Receive((Span<byte>)buffer, SocketFlags.None)); | ||
| public override Task<int> SendAsync(Socket s, ArraySegment<byte> buffer) => | ||
| Task.Run(() => s.Send((ReadOnlySpan<byte>)buffer, SocketFlags.None)); | ||
| public override bool UsesSync => true; |
There was a problem hiding this comment.
I guess this was missing by mistake. The property seemed useful for my tests.
|
@scalablecory @davidsh I just realized that my current changes are repeating the mistake pointed out in dotnet/corefx#40952. My understanding is that simply replacing the conditional block with Can I address both issues in this PR, or shall I open a separate one? |
It's going to need more than a CAS. Here's what I'm seeing (each snip being a context switch)
runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs Lines 3340 to 3343 in eae85a0
runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs Lines 2718 to 2721 in eae85a0
runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs Lines 3349 to 3353 in eae85a0
I think that's fine. |
|
/azp run runtime-libraries outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@dotnet/ncl after a further analysis testing of the code, my opinion got even stronger that we should handle the two topics separately. After we decide exactly how we change the way I removed the no merge label, and marking this PR ready to review as is. |
|
A WebSocket and an Http outerloop test failed on linux. |
scalablecory
left a comment
There was a problem hiding this comment.
The other methods null out _rightEndPoint if the API call fails. We should be doing this here too, in the catch block below your change.
|
fixes #915 |
| catch | ||
| { | ||
| _rightEndPoint = null; | ||
| // Clear in-use flag on event args object. | ||
| e.Complete(); | ||
| throw; | ||
| } | ||
|
|
||
| if (!CheckErrorAndUpdateStatus(socketError)) | ||
| { |
There was a problem hiding this comment.
I have no idea what black magic could trigger the catch block here, on the other hand socketError == AccessDenied is something we can actually hit, see my test cases. Like in DoBeginSendTo I'm resetting _rightEndPoint when hitting a non-success & non-pending case.
|
@scalablecory just addressed your findings + did some test improvements:
|
|
Test failures are tracked under #1332 and unrelated to Sockets. |
|
@antonfirsov is this missing a breaking change doc issue? If so can you please open one with https://github.com/dotnet/docs/issues/new?template=dotnet-breaking-change.md |
Fixes #915 by assigning
_rightEndPointlike in other overloads, introducing a breaking change in the behavior ofSendToAsync(SocketAsyncEventArgs).Fixes #915