Shutdown socket in some cases to prevent endless hang on blocking operation#32087
Shutdown socket in some cases to prevent endless hang on blocking operation#32087wfurt wants to merge 14 commits intodotnet:masterfrom
Conversation
| { | ||
| if ((AsyncContext == null || !AsyncContext.GetNonBlocking()) && innerSocket != null && !_underlyingHandleNonBlocking && !innerSocket.IsClosed && !innerSocket.IsInvalid) | ||
| { | ||
| // We only need to coll this for true blocking calls when there is chance they are stuck in OS system call. |
|
|
||
| public class BlockingSendReceive | ||
| { | ||
|
|
| server.BindToAnonymousPort(ipAddress); | ||
| server.Listen(1); | ||
| byte[] buffer = new byte[1]; | ||
| buffer[0] = Convert.ToByte('a'); |
There was a problem hiding this comment.
I don't think you need to use Convert here, you can just cast to byte, i.e. (byte)'a' -- we do this in product code in some places.
| buffer[0] = Convert.ToByte('a'); | ||
| server.BindToAnonymousPort(ipAddress); | ||
| server.Listen(1); | ||
| Task clientTask = Task.Run(() => |
There was a problem hiding this comment.
Seems like this should be called "serverTask" (and in the comment below)
| } | ||
|
|
||
| [Theory] | ||
| [PlatformSpecific(~TestPlatforms.OSX)] |
There was a problem hiding this comment.
Is there a separate issue for OSX? Can we link the issue here?
There was a problem hiding this comment.
not at the moment, both issues were reported on Linux. I can update #26034 and leave it open for OSX instead of closing.
| // Blocking read. | ||
| try | ||
| { | ||
| client.Receive(buffer); |
There was a problem hiding this comment.
What is the expected behavior here when we Close? Do we throw? Do we return 0 bytes? Seems like we should validate the expected behavior.
There was a problem hiding this comment.
It will throw one or the other exception in catch. It it throws something else or if it hangs, test should fail.
| // Each round will block until new connection is accepted. | ||
| while (true) | ||
| { | ||
| Socket serverSocket = server.Accept(); |
There was a problem hiding this comment.
What is the expected behavior here when we Close? Do we throw? Do we return null?
There was a problem hiding this comment.
As above, we should verify the expected behavior.
|
also fixes #31368. New test added. |
|
@dotnet-bot test Outerloop Linux x64 Debug Build |
|
Not touched in a long time, closing for now. Feel free to reopen when it is ready. |
reopening after #26898 was closed.
Fixes #22564
Fixes #26034