From 2ce70f038c8d67952bd3088cabf39e834159d505 Mon Sep 17 00:00:00 2001 From: fales1488 <31536110+fales1488@users.noreply.github.com> Date: Tue, 7 May 2024 14:26:18 +0300 Subject: [PATCH] Prevent division by zero in FairQueueing when no active pipes are available This commit fixes a potential DivideByZeroException in the FairQueueing class by conditionally performing the modulo operation only when there are active pipes (m_active > 0). This issue occurs during round-robin processing of messages when all pipes have been deactivated. The modification ensures stability and prevents crashes under these specific conditions. --- src/NetMQ/Core/Patterns/Utils/FairQueueing.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NetMQ/Core/Patterns/Utils/FairQueueing.cs b/src/NetMQ/Core/Patterns/Utils/FairQueueing.cs index c61d7579..2cabfdc2 100644 --- a/src/NetMQ/Core/Patterns/Utils/FairQueueing.cs +++ b/src/NetMQ/Core/Patterns/Utils/FairQueueing.cs @@ -122,7 +122,7 @@ public bool RecvPipe(ref Msg msg, [NotNullWhen(returnValue: true)] out Pipe? pip m_more = msg.HasMore; if (!m_more) - m_current = (m_current + 1) % m_active; + m_current = m_active > 0 ? (m_current + 1) % m_active : 0; return true; }