zeromq / netmq

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

Mailbox.TryRead still throwing in debug mode #1092

Open tmatthey opened 2 months ago

tmatthey commented 2 months ago

Environment

NetMQ Version:    4.0.1.13 with [PR 1087](https://github.com/zeromq/netmq/pull/1087) debug mode
Operating System:  Alpine Linux
.NET Version:   standard 2.0  

Expected behaviour

Mailbox.TryRead should not throw when returning a command for debug mode.

Actual behaviour

When run in debug mode Debug.Assert(ok); may throw since m_commandPipe.TryRead may return false:

Process terminated. Assertion failed.
   at NetMQ.Core.Mailbox.TryRecv(Int32 timeout, Command& command)
   at NetMQ.Core.SocketBase.ProcessCommands(Int32 timeout, Boolean throttle, CancellationToken cancellationToken)
   at NetMQ.Core.SocketBase.GetSocketOptionX(ZmqSocketOption option)
   at NetMQ.NetMQSocket.GetSocketOptionX[T](ZmqSocketOption option)
   at NetMQ.NetMQSocket.get_HasIn()

Steps to reproduce the behaviour

A one-off on Alpine Linux, most probably when DNS disappears.

How to potentially fix

Remove Debug.Assert(ok);, just return value of m_commandPipe.TryRead. I'm not certain if caller of Mailbox.TryRead may check if command.Destination to be not zero when processing the command, i.e., reading a command with CommandType.Done sent by ZObject.SendDone(), which has no destination.