zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.95k stars 744 forks source link

NetMQMonitor Crash #1006

Open jgasperlin opened 2 years ago

jgasperlin commented 2 years ago

Environment

NetMQ Version:    4.0.1.6
Operating System: Windows
.NET Version: 6.0

Expected behavior

Monitoring of socket connection

Actual behavior

Crash during unit testing, connecting and disconnection multiple clients.

Steps to reproduce the behavior

Use RouterSocket and assign new NetMQMonitor(Socket, monitorEndpoint, SocketEvents.Disconnected | SocketEvents.Accepted). Monitor accepted connection with on event _monitor.Accepted.

When exception is throw on line https://github.com/zeromq/netmq/blob/0b58c232799ce578868524814ce7a59ed13a0a37/src/NetMQ/Monitoring/NetMQMonitor.cs#L159 it crashes application.

System.ArgumentException: Command argument must be of type AsyncSocket.
   at NetMQ.Monitoring.NetMQMonitor.<Handle>g__GetArg|51_0[T](<>c__DisplayClass51_0& )
   at NetMQ.Monitoring.NetMQMonitor.Handle(Object sender, NetMQSocketEventArgs socketEventArgs)
   at NetMQ.NetMQSocket.InvokeEvents(Object sender, PollEvents events)
   at NetMQ.NetMQPoller.RunPoller()
   at NetMQ.NetMQPoller.Run(SynchronizationContext syncContext)
   at NetMQ.NetMQPoller.Run()
   at System.Threading.Thread.StartHelper.Callback(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Thread.StartCallback()

I tested with some shorter/longer event handlers, but did not make difference. When I added conditional breakpoint on https://github.com/zeromq/netmq/blob/0b58c232799ce578868524814ce7a59ed13a0a37/src/NetMQ/Monitoring/NetMQMonitor.cs#L159 it never hit again. (Most likely do to slower performance) Am assuming problem is on not yet initializes socket while event is already being propagated.

284093959 commented 1 year ago

Hello, I have encountered the same problem, have you find the cause or has it been solved?

The-Naruto commented 1 year ago

Hello, I have encountered the same problem, have you find the cause or has it been solved?

hello,I‘m handling the same problem ,have you has it been solved?