Skip to content

Commit 03c96e9

Browse files
Copilotdrewnoakes
andauthored
Fix macOS Socket.Select hang: pass null errorList to avoid dotnet/corefx#39617
Agent-Logs-Url: https://github.com/zeromq/netmq/sessions/c84022ee-fa21-46a4-9cea-b5920dcf2ab5 Co-authored-by: drewnoakes <[email protected]>
1 parent 7c9a97f commit 03c96e9

1 file changed

Lines changed: 6 additions & 37 deletions

File tree

src/NetMQ/Core/Utils/Poller.cs

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ public void Stop()
259259
private void Loop()
260260
{
261261
var readList = new List<Socket>();
262-
// var writeList = new List<Socket>();
263-
var errorList = new List<Socket>();
264262

265263
while (!m_stopping)
266264
{
@@ -272,13 +270,16 @@ private void Loop()
272270
int timeout = ExecuteTimers();
273271

274272
readList.AddRange(m_checkRead.ToArray());
275-
// writeList.AddRange(m_checkWrite.ToArray());
276-
errorList.AddRange(m_checkError.ToArray());
277273

278274
try
279275
{
280276
timeout = timeout != 0 ? timeout * 1000 : -1;
281-
Socket.Select(readList, null, errorList, timeout);
277+
// Pass null for the error list: every socket is already tracked in
278+
// m_checkRead (callers always invoke SetPollIn after AddHandle), so
279+
// socket errors surface as readable events too. Passing a non-null
280+
// error list alongside readList causes Socket.Select to hang
281+
// indefinitely on macOS .NET (https://github.com/dotnet/corefx/issues/39617).
282+
Socket.Select(readList, null, null, timeout);
282283
}
283284
catch (SocketException)
284285
{
@@ -291,36 +292,6 @@ private void Loop()
291292
if (pollSet.Cancelled)
292293
continue;
293294

294-
// Invoke its handler's InEvent if it's in our error-list.
295-
if (errorList.Contains(pollSet.Socket))
296-
{
297-
try
298-
{
299-
pollSet.Handler.InEvent();
300-
}
301-
catch (TerminatingException)
302-
{
303-
}
304-
}
305-
306-
if (pollSet.Cancelled)
307-
continue;
308-
309-
// // Invoke its handler's OutEvent if it's in our write-list.
310-
// if (writeList.Contains(pollSet.Socket))
311-
// {
312-
// try
313-
// {
314-
// pollSet.Handler.OutEvent();
315-
// }
316-
// catch (TerminatingException)
317-
// {
318-
// }
319-
// }
320-
//
321-
// if (pollSet.Cancelled)
322-
// continue;
323-
324295
// Invoke its handler's InEvent if it's in our read-list.
325296
if (readList.Contains(pollSet.Socket))
326297
{
@@ -334,8 +305,6 @@ private void Loop()
334305
}
335306
}
336307

337-
errorList.Clear();
338-
// writeList.Clear();
339308
readList.Clear();
340309

341310
if (m_retired)

0 commit comments

Comments
 (0)