Poller will throw ObjectDisposed exception if Socket.Dispose() called #834
Description
Environment
NetMQ Version: 4.0.0.2
Operating System: Win 10
.NET Version: Standard 2.0 / Core
Expected behaviour
poller.Remove(socket);
socket.Dispose();
should remove the socket from the poller's list, and then dispose the socket, poller should continue to run servicing other sockets.
Actual behaviour
poller throws ObjectDisposedException
after socket.Dispose()
is called
Steps to reproduce the behaviour
This code in a unit test:
poller.Remove(socket);
socket.Dispose();
Causes an ObjectDisposedException error to throw on the poller's thread from SocketBase.CheckDisposed()
, and kill my unit test runtime.
There needs to be some better syncing on Poller.Remove()
so that it blocks the the poller's thread and/or the caller of Remove() such that the Remove does not return until that socket is actually removed from the poller's internal list. This is the issue as it is currently written.
I would argue that CheckDisposed()
should return a bool so that poller can not try to access that socket, and avoid throwing the exception.
I can't find a path to calling Socket.Dispose()
after it has been passed to Poller.Add(Socket)
and Poller.RunAsync()
is called that doesn't throw.