Skip to content

Don't retain a message that max_active_messages rejected - #164

Merged
dallison merged 2 commits into
mainfrom
fix-retained-active-message
Nov 21, 2026
Merged

dallison merged 2 commits into
mainfrom
fix-retained-active-message

Conversation

@dallison

Copy link
Copy Markdown
Owner

Problem

When a subscriber keeps its current message (reliable or keep_active_message) and SetActiveMessage() is called while the subscriber is already at max_active_messages, ActiveMessage::Set() clears the message (length == 0) but SetActiveMessage() still retained it and took a reference.

That leaves refs == 1 with length == 0. On the next ReadMessage(), HoldExistingMessage() finds the slot, sees length == 0, sets rejected, and returns before ClearActiveMessage() can drop the reference. The subscriber never reads again.

Change

  • SubscriberImpl::SetActiveMessage() retains only a message that was actually taken (m->length > 0).
  • Adds ClientTest.RetainedSubscriberRecoversAfterMaxActiveMessages, which covers the reliable and keep_active_message cases: hold the first message, see the second read come back empty, release the first, then read the second.
  • MODULE.bazel micro version bumped to 3.4.3.

Testing

  • The new test fails on the unfixed subscriber.h (second->length is 0) and passes with the fix.
  • bazelisk test //client:client_test --config=macos_arm64 (with USE_BAZEL_VERSION=9.3.2): full suite passes.

Base branch is main; there is no develop branch on the remote.

SetActiveMessage() retained the ActiveMessage for subscribers that keep
their current message (reliable or keep_active_message) even when Set()
had already cleared it because max_active_messages was reached. The
retained reference left refs == 1 with length == 0. The next read then
found the slot in HoldExistingMessage, saw length == 0, set rejected, and
returned before ClearActiveMessage could drop that reference. The
subscriber could not read again.

Retain only a message that was actually taken (length > 0).

ClientTest.RetainedSubscriberRecoversAfterMaxActiveMessages covers the
reliable and keep_active_message cases: hold the first message, see the
second read come back empty, release the first, then read the second. It
fails on the old code and passes with this change.
@dallison
dallison merged commit 018f47e into main Nov 21, 2026
52 checks passed
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.

1 participant