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

Socket.Poll(μsTimeout, SelectMode.SelectRead) behavior is confusing #32719

Closed
luigiberrettini opened this issue Feb 23, 2020 · 3 comments · Fixed by dotnet/dotnet-api-docs#8485
Assignees
Labels
area-System.Net.Sockets documentation Documentation bug or enhancement, does not impact product or test code
Milestone

Comments

@luigiberrettini
Copy link
Contributor

Opened as suggested by @karelz when closing #26209

Microsoft Docs say that Socket.Poll:

  • will block execution until the specified time period, measured in microseconds, elapses
  • cannot detect certain kinds of connection problems, such as a broken network cable,
    or that the remote host was shut down ungracefully (you must attempt to send or receive data to detect these kinds of errors)
  • when used with SelectMode.SelectRead returns:
    • true if Listen(Int32) has been called and a connection is pending
    • true if data is available for reading
    • true if the connection has been closed, reset, or terminated
    • false otherwise

As per my understanding, when the server is up and the connection ok, Socket.Poll with SelectMode.SelectRead should return false immediately.
Unfortunately this doesn't happen and a delay is experienced, due to the timeout expiring: this test fails on the last Assert.Equal() since the actual result is different from the Expected: 0.

It would be great is someone could describe the intended behavior of Socket.Poll with SelectMode.SelectRead:

  • returning true only after the timeout elapses and returning false immediately
  • returning false only after the timeout elapses and returning true immediately
  • returning any result only after the timeout elapses
  • returning any result immediately
  • other

Is this behavior the same for every SocketType and ProtocolType combination, included the ones used to create the Socket returned by the TcpClient and UdpClient constructors?

I am asking this because UDP is a connectionless protocol therefore a call to Poll could result in a different behavior since there is no connection to be "checked".

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net untriaged New issue has not been triaged by the area owner labels Feb 23, 2020
@karelz
Copy link
Member

karelz commented Mar 12, 2020

Triage: We don't think we will change any APIs behavior even if it is confusing -- documenting the behavior seems like the best choice.

@karelz karelz added this to the Future milestone Mar 12, 2020
@karelz karelz added documentation Documentation bug or enhancement, does not impact product or test code and removed untriaged New issue has not been triaged by the area owner labels Mar 12, 2020
@upsampled
Copy link

upsampled commented Dec 10, 2020

Any initial progress on the documentation? Or at least a recommendation of another api call that can produce the desired behavior of determining if a:

  • socket is readable
  • socket is not-readable
  • an error occurred: could not determine readability, try again

In a bounded period of time?

@ghost
Copy link

ghost commented Oct 5, 2022

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

Issue Details

Opened as suggested by @karelz when closing #26209

Microsoft Docs say that Socket.Poll:

  • will block execution until the specified time period, measured in microseconds, elapses
  • cannot detect certain kinds of connection problems, such as a broken network cable,
    or that the remote host was shut down ungracefully (you must attempt to send or receive data to detect these kinds of errors)
  • when used with SelectMode.SelectRead returns:
    • true if Listen(Int32) has been called and a connection is pending
    • true if data is available for reading
    • true if the connection has been closed, reset, or terminated
    • false otherwise

As per my understanding, when the server is up and the connection ok, Socket.Poll with SelectMode.SelectRead should return false immediately.
Unfortunately this doesn't happen and a delay is experienced, due to the timeout expiring: this test fails on the last Assert.Equal() since the actual result is different from the Expected: 0.

It would be great is someone could describe the intended behavior of Socket.Poll with SelectMode.SelectRead:

  • returning true only after the timeout elapses and returning false immediately
  • returning false only after the timeout elapses and returning true immediately
  • returning any result only after the timeout elapses
  • returning any result immediately
  • other

Is this behavior the same for every SocketType and ProtocolType combination, included the ones used to create the Socket returned by the TcpClient and UdpClient constructors?

I am asking this because UDP is a connectionless protocol therefore a call to Poll could result in a different behavior since there is no connection to be "checked".

Author: luigiberrettini
Assignees: liveans
Labels:

documentation, area-System.Net.Sockets

Milestone: Future

@ghost ghost locked as resolved and limited conversation to collaborators Nov 10, 2022
@karelz karelz modified the milestones: Future, 8.0.0 Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Sockets documentation Documentation bug or enhancement, does not impact product or test code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants