GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][client] Release the reserved memory only once when failing a send in a terminal state by SongOf · Pull Request #26476 · apache/pulsar

Conversation

@SongOf

@SongOf SongOf commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Motivation

ProducerImpl#processOpSendMsg fails a message immediately when the producer is in a terminal
state (Terminated / Closed / ProducerFenced) instead of leaving it in pendingMessages
until the send timeout fires. That path releases the memory reserved for the message twice:

releaseSemaphoreForSendOp(op);
client.getMemoryLimitController().releaseMemory(op.uncompressedSize);

releaseSemaphoreForSendOp(op) already returns op.uncompressedSize to the
MemoryLimitController, so the explicit call right after it releases the same bytes a second
time.

MemoryLimitController only validates that the argument is non-negative, not that the running
total stays sane, so this fails silently: every message published after the producer reaches a
terminal state drives currentUsage further below zero. Once it is negative,
tryReserveMemory() never returns false again and memoryLimitBytes is effectively disabled
for the whole client — every producer and consumer sharing that PulsarClient loses its memory
limit, which is exactly the protection that is supposed to keep the client from running out of
memory. An application that keeps publishing to a terminated topic, or that publishes after the
producer was fenced, hits this on every send.

This is a regression from #25317, which introduced the terminal-state fast-fail branch.

Modifications

  • ProducerImpl#processOpSendMsg: drop the redundant
    client.getMemoryLimitController().releaseMemory(op.uncompressedSize) from the terminal-state
    branch, leaving the single release performed by releaseSemaphoreForSendOp(op). Added a short
    comment recording that releaseSemaphoreForSendOp() already gives the reserved memory back, so
    the call is not re-added later.

No other path changes: the semaphore permits, the send callback, the ByteBufPair release and
the OpSendMsg recycling in that branch are untouched.

Verifying this change

This change added tests and can be verified as follows:

  • ProducerImplTest#testProcessOpSendMsgInTerminalStateReleasesMemoryOnce — reserves a known
    number of bytes in a real MemoryLimitController, drives processOpSendMsg() once for each of
    the three terminal states (Terminated, Closed, ProducerFenced), and asserts that
    currentUsage() returns to exactly 0. On the unpatched code it fails with
    expected [0] but found [-128], i.e. for the real reason — the double release — rather than by
    forcing internal state. The OpSendMsg is built through the batched factory so that op.msg is
    null, which keeps the test on the memory-accounting path and out of the batch-flush and
    message-size checks.

Local run:

./gradlew :pulsar-client-original:test --tests "ProducerImplTest" -PtestRetryCount=0
BUILD SUCCESSFUL

./gradlew rat spotlessCheck checkstyleMain checkstyleTest
BUILD SUCCESSFUL

The whole :pulsar-client-original:test module also passes.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

This is an internal bug fix in the client send path. It changes no public API, schema,
configuration default, wire protocol, REST endpoint, CLI option or metric; it restores the
intended behaviour of the existing memoryLimitBytes setting rather than changing it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@song-of-bot
[fix][client] Release the reserved memory only once when failing a se…
0fe4151
…nd in a terminal state
nodece
nodece approved these changes Sep 8, 2026
View reviewed changes
nodece
nodece approved these changes Sep 9, 2026
View reviewed changes
@nodece
nodece merged commit 698192d into apache:master Sep 9, 2026
44 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodece nodece added release/4.2.5 release/4.0.14 labels Sep 9, 2026
@nodece nodece added this to the 5.0.0-M2 milestone Sep 9, 2026
lhotari pushed a commit that referenced this pull request Sep 9, 2026
@SongOf @song-of-bot @lhotari
[fix][client] Release the reserved memory only once when failing a se…
6a5b19d
…nd in a terminal state (#26476)

Co-authored-by: maxlisongsong <[email protected]>
(cherry picked from commit 698192d)
@lhotari lhotari added the cherry-picked/branch-4.2 label Sep 9, 2026
lhotari pushed a commit that referenced this pull request Sep 9, 2026
@SongOf @song-of-bot @lhotari
[fix][client] Release the reserved memory only once when failing a se…
e3842de
…nd in a terminal state (#26476)

Co-authored-by: maxlisongsong <[email protected]>
(cherry picked from commit 698192d)
@lhotari lhotari added the cherry-picked/branch-4.0 label Sep 9, 2026
Radiancebobo pushed a commit to Radiancebobo/pulsar that referenced this pull request Oct 8, 2026
@SongOf @song-of-bot hechengbo
[fix][client] Release the reserved memory only once when failing a se…
b503e19
…nd in a terminal state (apache#26476)

Co-authored-by: maxlisongsong <[email protected]>
@nodece nodece mentioned this pull request Nov 5, 2026
[fix][ml][broker][client] Sync branch-as-4.0 with apache branch-4.0 (2026-09 to 2026-11, 159 commits) ascentstream/pulsar#109
Merged
4 of 5 tasks
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
@SongOf @song-of-bot @nodece
[fix][client] Release the reserved memory only once when failing a se…
013ff7c
…nd in a terminal state (apache#26476)

Co-authored-by: maxlisongsong <[email protected]>
(cherry picked from commit 698192d)
@xh123637 xh123637 mentioned this pull request Nov 24, 2026
[Bug] ProducerImpl releases a message's memory reservation twice in the terminal-state branch, permanently degrading the client memory limit #26469
Open
2 of 3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nodece nodece nodece approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 release/4.0.14 release/4.2.5

Projects

None yet

Milestone

5.0.0-M2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@SongOf @nodece @lhotari @song-of-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.