Skip to content

Fix[bmqp::RequestManager]: handle int32 signed overflow - #1715

Open
678098 wants to merge 1 commit into
bloomberg:mainfrom
678098:260814_bmqp_RequestManager_request_overflow
Open

Fix[bmqp::RequestManager]: handle int32 signed overflow#1715
678098 wants to merge 1 commit into
bloomberg:mainfrom
678098:260814_bmqp_RequestManager_request_overflow

Conversation

@678098

@678098 678098 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator
  • Wrap to 1 on reaching int32::max() when selecting the next requestId
  • Attempt to find the next unused requestId in a map

- Wrap to 1 on reaching int32::max() when selecting the next requestId
- Attempt to find the next unused requestId in a map

Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
@678098
678098 requested a review from a team as a code owner August 14, 2026 20:32
@678098
678098 requested a review from hallfox August 14, 2026 20:32
d_nextRequestId = (d_nextRequestId == k_LAST_REQUEST_ID)
? k_FIRST_REQUEST_ID
: d_nextRequestId + 1;
} while (d_requests.find(d_nextRequestId) != d_requests.end());

@678098 678098 Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lookup should be performed just once every time we call this function, before we reach 2.147kk requests.
If we reached it, we might theoretically have multiple iterations of this loop.
What do you think? Is it worth attempting to find the next unused rId?

// Insert the request in the map
BSLA_MAYBE_UNUSED bsl::pair<RequestMapIter, bool> insertRC =
d_requests.insert(bsl::make_pair(requestId, request));
BSLS_ASSERT_SAFE(insertRC.second);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code might have failed on int32::max wrap without an attempt to find next; with this PR, we are guaranteed to find the next unused.
Also, changing this to ASSERT_OPT

: d_nextRequestId + 1;
} while (d_requests.find(d_nextRequestId) != d_requests.end());

return d_nextRequestId;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is also difficult to test.
UT that calls bmqp::RequestManager::sendRequest 2kkk times might take hours to execute. The only way to write a good test is to expose bmqp::RequestManager internal state to fast-forward d_nextRequestId

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

Successfully merging this pull request may close these issues.

2 participants