{"action":"opened","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/11174","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/11174/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/11174/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/11174/events","html_url":"https://github.com/dotnet/corefx/issues/11174","id":173376966,"number":11174,"title":"Socket Poll during non-blocking connect broken on linux","user":{"login":"ThadHouse","id":7727148,"avatar_url":"https://avatars.githubusercontent.com/u/7727148?v=3","gravatar_id":"","url":"https://api.github.com/users/ThadHouse","html_url":"https://github.com/ThadHouse","followers_url":"https://api.github.com/users/ThadHouse/followers","following_url":"https://api.github.com/users/ThadHouse/following{/other_user}","gists_url":"https://api.github.com/users/ThadHouse/gists{/gist_id}","starred_url":"https://api.github.com/users/ThadHouse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThadHouse/subscriptions","organizations_url":"https://api.github.com/users/ThadHouse/orgs","repos_url":"https://api.github.com/users/ThadHouse/repos","events_url":"https://api.github.com/users/ThadHouse/events{/privacy}","received_events_url":"https://api.github.com/users/ThadHouse/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-26T06:09:28Z","updated_at":"2016-08-26T06:09:28Z","closed_at":null,"body":"I am writing a library that requires a timeout on a socket connection from a client to a server. I tried implementing this using async methods, however this library needs to support net451 and netstandard, which both do not support the same async methods. In C previously, I've seen programs that do a non blocking connect() call, and the a poll() call to detect if the socket has finally connected, and timing out after enough poll failures have passed. The code below is a simplified version of what I have ported, and it works perfectly on windows, both with .net 4.5.1 and .net core RTM. The poll call returns false and loops until timeout. However, on linux and mac, the poll call always returns true, even when I can verify there is no socket listening on that port. If I try to call connect after the poll call returns true, I end up getting a ConnectionRefused error code. Is there a specific setting that would need to be called additionally on unix systems to make this work properly, or is this an internal library issue?\r\n\r\n```\r\nSocket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);\r\n\r\nsocket.Blocking=false;\r\n\r\ntry {\r\n  socket.Connect(IPAddress.Loopback, 2222);\r\n} catch (SocketException ex) {\r\n  if (ex.SocketErrorCode == SocketError.WouldBlock || ex.SocketErrorCode == SocketError.InProgress) {\r\n    while (true) {\r\n      if (socket.Poll(1000, SelectMode.SelectWrite) {\r\n        // Socket connected (or should be anyway)\r\n        return;\r\n      } else {\r\n        // Check if timed out here\r\n      }\r\n    }\r\n  }\r\n}\r\n```"}}
{"actor":{"display_login":"ThadHouse"}}