Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Division by Zero Error in FairQueueing Class When m_active is Zero #1088

Closed
fales1488 opened this issue May 7, 2024 · 0 comments
Closed

Comments

@fales1488
Copy link
Contributor

m_current = (m_current + 1) % m_active;

Description

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

  1. Create a scenario where all pipes are systematically deactivated, setting m_active to zero.
  2. 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:

if (!m_more)
    m_current = m_active > 0 ? (m_current + 1) % m_active : 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants