There is a potential DivideByZeroException in the FairQueueing class of NetMQ when all pipes become deactivated (m_active becomes zero). This exception occurs specifically in the RecvPipe method during the modulo operation used for round-robin scheduling of the pipes.
Steps to Reproduce
Create a scenario where all pipes are systematically deactivated, setting m_active to zero.
Continue to receive messages or perform operations that lead to the modulo operation (m_current = (m_current + 1) % m_active).
Expected Behavior
The system should handle situations where m_active is zero without throwing a DivideByZeroException, possibly by skipping the modulo operation when no active pipes are available.
Actual Behavior
The system throws a DivideByZeroException when trying to perform the modulo operation with m_active set to zero due to all pipes being deactivated.
Proposed Solution
To prevent this issue, the modulo operation in the RecvPipe method should be conditionally performed only when m_active is greater than zero. Here is the suggested change:
https://github.com/zeromq/netmq/blob/97da3b46ba768eb5050547276a9ef948741a9de4/src/NetMQ/Core/Patterns/Utils/FairQueueing.cs#L125
Description
There is a potential
DivideByZeroException
in theFairQueueing
class of NetMQ when all pipes become deactivated (m_active
becomes zero). This exception occurs specifically in theRecvPipe
method during the modulo operation used for round-robin scheduling of the pipes.Steps to Reproduce
m_active
to zero.m_current = (m_current + 1) % m_active
).Expected Behavior
The system should handle situations where
m_active
is zero without throwing aDivideByZeroException
, possibly by skipping the modulo operation when no active pipes are available.Actual Behavior
The system throws a
DivideByZeroException
when trying to perform the modulo operation withm_active
set to zero due to all pipes being deactivated.Proposed Solution
To prevent this issue, the modulo operation in the
RecvPipe
method should be conditionally performed only whenm_active
is greater than zero. Here is the suggested change: