Skip to content

[fix][broker] Fix race in pending acks removal in redeliverUnacknowledgedMessages#25589

Merged
nodece merged 1 commit into
apache:masterfrom
nodece:redeliver-expire-race
Apr 28, 2026
Merged

[fix][broker] Fix race in pending acks removal in redeliverUnacknowledgedMessages#25589
nodece merged 1 commit into
apache:masterfrom
nodece:redeliver-expire-race

Conversation

@nodece
Copy link
Copy Markdown
Member

@nodece nodece commented Apr 28, 2026

Motivation

Consumer.redeliverUnacknowledgedMessages has race conditions with the expire path (readMoreEntries → removeAllUpTo), which can corrupt the unackedMessages counter:

  • The epoch-based variant resets the counter to 0, while expire may concurrently decrement it to a negative value.
  • The list-based variant performs get and remove separately, allowing expire to remove entries in between and causing incorrect redelivery counting.

Modifications

  • Make redelivery operations atomic with respect to expire:

    • Add PendingAcksMap.forEachAndClear() to atomically iterate and clear all entries under a single lock.
    • Add PendingAcksMap.removeAndGet() to atomically get and remove entries.

Copy link
Copy Markdown
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

LGTM. Good catch! Just thinking that the usage of "expire" is slightly misleading in the title since it could be confused with "message expiration". An alternative title could be "Fix race in pending acks removal in redeliverUnacknowledgedMessages"

@nodece nodece changed the title [fix][broker] Fix race between redeliverUnacknowledgedMessages and expire [fix][broker] Fix race in pending acks removal in redeliverUnacknowledgedMessages Apr 28, 2026
@nodece nodece merged commit 9e1bae3 into apache:master Apr 28, 2026
81 of 84 checks passed
@nodece nodece deleted the redeliver-expire-race branch April 28, 2026 07:19
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request May 6, 2026
Technoboy- added a commit that referenced this pull request May 12, 2026
lhotari pushed a commit that referenced this pull request May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants