Skip to content

Avoid infinite loop in DeltaManager with invalid batch size - #1042

Merged
markt-asf merged 1 commit into
apache:mainfrom
lihongyi87:fix-deltamanager-sendallsessionssize-loop
Aug 18, 2026
Merged

Avoid infinite loop in DeltaManager with invalid batch size#1042
markt-asf merged 1 commit into
apache:mainfrom
lihongyi87:fix-deltamanager-sendallsessionssize-loop

Conversation

@lihongyi87

Copy link
Copy Markdown
Contributor

Problem

When sendAllSessions is false and sendAllSessionsSize is configured to zero or a negative value, the batch loop in handleGET_ALL_SESSIONS never terminates:

for (int i = 0; i < currentSessions.length; i += getSendAllSessionsSize()) {
  • With sendAllSessionsSize == 0: i never advances, so the loop runs indefinitely, sending empty session arrays and sleeping on each iteration. This blocks the cluster receiver thread on the master node and prevents EVT_ALL_SESSION_TRANSFERCOMPLETE from ever being sent.
  • With sendAllSessionsSize < 0: i decreases, and new Session[len] throws NegativeArraySizeException.

The setSendAllSessionsSize setter performs no validation, and the documentation (cluster-manager.xml) does not state a minimum value.

Fix

When sendAllSessionsSize is not positive, fall back to sending all sessions in a single batch (the same behaviour as sendAllSessions == true):

if (isSendAllSessions() || getSendAllSessionsSize() <= 0) {

This is a one-line change at the point of use, keeping the setter unmodified for consistency with the rest of DeltaManager.

@lihongyi87
lihongyi87 force-pushed the fix-deltamanager-sendallsessionssize-loop branch 4 times, most recently from a930578 to 2dc4e64 Compare August 14, 2026 05:48
@markt-asf

Copy link
Copy Markdown
Contributor

I'd rather document that sendAllSessionsSize must be a positive integer and throw IllegalArgumentException if it isn't.

@lihongyi87
lihongyi87 force-pushed the fix-deltamanager-sendallsessionssize-loop branch from 2dc4e64 to 0297ebb Compare August 14, 2026 13:34
@lihongyi87

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Reworked as suggested: the setter now rejects a non-positive sendAllSessionsSize with an IllegalArgumentException, the documentation states the value must be a positive integer, and the fallback in handleGET_ALL_SESSIONS has been reverted. Tests updated accordingly.

Comment on lines +322 to +328
<fix>
Validate that the <code>DeltaManager</code> attribute
<code>sendAllSessionsSize</code> is a positive integer. Zero or
negative values previously caused an infinite loop or a
<code>NegativeArraySizeException</code> during session state transfer.
(lihongyi87)
</fix>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to be below the line since it will be back-ported.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved below the line. Thanks for the pointer.

Reject a sendAllSessionsSize of zero or less with an
IllegalArgumentException in the setter and document that the value
must be a positive integer. Previously a non-positive value caused
an infinite loop or a NegativeArraySizeException in the batching
loop of handleGET_ALL_SESSIONS.
@lihongyi87
lihongyi87 force-pushed the fix-deltamanager-sendallsessionssize-loop branch from 0297ebb to 6344885 Compare August 18, 2026 01:37
@markt-asf
markt-asf merged commit 318032a into apache:main Aug 18, 2026
markt-asf pushed a commit that referenced this pull request Aug 18, 2026
Reject a sendAllSessionsSize of zero or less with an
IllegalArgumentException in the setter and document that the value
must be a positive integer. Previously a non-positive value caused
an infinite loop or a NegativeArraySizeException in the batching
loop of handleGET_ALL_SESSIONS.

Clean-up by markt
markt-asf pushed a commit that referenced this pull request Aug 18, 2026
Reject a sendAllSessionsSize of zero or less with an
IllegalArgumentException in the setter and document that the value
must be a positive integer. Previously a non-positive value caused
an infinite loop or a NegativeArraySizeException in the batching
loop of handleGET_ALL_SESSIONS.

Clean-up by markt
markt-asf pushed a commit that referenced this pull request Aug 18, 2026
Reject a sendAllSessionsSize of zero or less with an
IllegalArgumentException in the setter and document that the value
must be a positive integer. Previously a non-positive value caused
an infinite loop or a NegativeArraySizeException in the batching
loop of handleGET_ALL_SESSIONS.

Clean-up by markt
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