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][proxy] Copy GetTopicsOfNamespace properties before the broker connection completes by lhotari · Pull Request #27055 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Oct 22, 2026

Copy link
Copy Markdown
Member

Motivation

PulsarDecoder.channelRead parses every frame into one BaseCommand that is reused for the whole connection, and releases the frame buffer once the handleXxx(...) method returns. LightProto decodes string fields lazily from that buffer, and BaseCommand.clear() resets the child command when the next frame arrives. A handler must therefore not read the command, or nested messages obtained from it, inside an async continuation. This is the same class of problem as #27050.

LookupProxyHandler.handleGetTopicsOfNamespace passed commandGetTopicsOfNamespace.getPropertiesList(), which holds the decoder's reused KeyValue objects, to performGetTopicsOfNamespace. That method only read kv.getKey() / kv.getValue() inside the ConnectionPool.getConnection(addr).thenAccept(...) callback. When the pool has to open a new connection to the broker, the frame buffer has already been released by the time the callback runs. The proxy then answers the client with IllegalReferenceCountException: refCnt: 0, or it forwards properties decoded from recycled memory or from another request on the same connection. Only GetTopicsOfNamespace requests that carry properties are affected.

When the bug was introduced: in 4a88612, "[feat][broker] PIP-452: Customizable topic listing of namespace with properties (#25160)" (2026-02-12). It was released in 4.2.0, and every 4.2.x release since contains it. Of the maintained release branches, only branch-4.2 has the code; branch-3.0, branch-3.3, branch-4.0 and branch-4.1 don't have the feature.

A related issue in the same class, reading isMetadataAutoCreationEnabled() from the reused partitioned-metadata command inside the connection callback, was already fixed on master by #26607. That one dates back to #22206 (PIP-344, 2024-05-23) and is still present on branch-3.0, branch-3.3, branch-4.0, branch-4.1 and branch-4.2, so those branches need #26607 (or at least its capture of the flag) backported.

Modifications

  • In handleGetTopicsOfNamespace, copy the GetTopicsOfNamespace properties into a Map<String, String> before the first async boundary. Pass the map down to performGetTopicsOfNamespace instead of the List<KeyValue>.
  • The other lookup paths in LookupProxyHandler already capture what they need before the async boundary: lookup, partitioned metadata (after [fix][proxy] Answer failed partition metadata and lookup requests with their own response type #26607) and get schema.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Added LookupProxyHandlerTest.testGetTopicsOfNamespaceCopiesPropertiesBeforeConnecting. It parses a GetTopicsOfNamespace frame into a reused BaseCommand and calls the handler while the broker connection is pending. It then releases the frame and parses another request into the same command, as the decoder does. Finally it completes the connection and asserts that the request forwarded to the broker carries the original properties. Without the fix, the proxy answers with IllegalReferenceCountException: refCnt: 0 and nothing is forwarded.

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

Sorry, something went wrong.

Uh oh!

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

All reactions
@lhotari
[fix][proxy] Copy GetTopicsOfNamespace properties before the broker c…
9acab8c
…onnection completes

PulsarDecoder parses every frame into a reused BaseCommand and releases the
frame buffer once the handler returns. LookupProxyHandler passed the
command's lazily decoded KeyValue list into the connection future callback,
so the properties could be read after the buffer was released or after the
command was reused for another frame. Copy the properties into a map before
the first async boundary.

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari
lhotari requested review from Technoboy-, codelipenghui, dao-jun, merlimat and nodece October 22, 2026 21:45
@lhotari lhotari added the release/4.2.6 label Oct 22, 2026
@merlimat merlimat added this to the 5.1.0 milestone Oct 22, 2026
merlimat
merlimat approved these changes Oct 22, 2026
View reviewed changes
Comment thread pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/LookupProxyHandler.java Resolved

Uh oh!

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

@merlimat merlimat added release/4.0.15 release/5.0.2 labels Oct 22, 2026
codelipenghui
codelipenghui approved these changes Oct 23, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM.

I tested it locally:

  • With LookupProxyHandler reverted to the parent commit and the new test kept, testGetTopicsOfNamespaceCopiesPropertiesBeforeConnecting fails. clientCnx.newGetTopicsOfNamespace is never called, so the request never reaches the broker.
  • With the fix, all 74 LookupProxyHandlerTest cases pass.

I also checked the generated LightProto 0.9.3 code. getPropertiesList() returns a shallow copy that still holds the pooled KeyValue instances. clear() only resets the count, and getKey()/getValue() decode lazily from the parsed buffer. Copying the properties into a map before the connection future is the right fix, and it matches the eager copy in ServerCnx.handleGetTopicsOfNamespace.

Minor, non-blocking: the PR has the release/4.0.15 label, but the description says branch-4.0 doesn't have PIP-452. Worth double-checking the backport targets.

Sorry, something went wrong.

Uh oh!

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

All reactions
@codelipenghui
codelipenghui merged commit 17166c8 into apache:master Oct 23, 2026
44 checks passed

Uh oh!

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

lhotari added a commit that referenced this pull request Oct 23, 2026
@lhotari
[fix][proxy] Copy GetTopicsOfNamespace properties before the broker c…
71b758c
…onnection completes (#27055)

(cherry picked from commit 17166c8)
@lhotari lhotari added the cherry-picked/branch-5.0 label Oct 23, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 and removed release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@lhotari
[fix][proxy] Copy GetTopicsOfNamespace properties before the broker c…
a4cf9ca
…onnection completes (apache#27055)

(cherry picked from commit 17166c8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merlimat merlimat merlimat approved these changes
@codelipenghui codelipenghui codelipenghui approved these changes
@nodece nodece Awaiting requested review from nodece
@dao-jun dao-jun Awaiting requested review from dao-jun
@Technoboy- Technoboy- Awaiting requested review from Technoboy-

Uh oh!

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

Assignees

No one assigned

Labels

cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

5.1.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

@lhotari @merlimat @codelipenghui
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.