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] Answer failed partition metadata and lookup requests with their own response type by void-ptr974 · Pull Request #26607 · apache/pulsar

Conversation

@void-ptr974

@void-ptr974 void-ptr974 commented Sep 16, 2026 •
edited by merlimat
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Motivation

When the proxy can't serve a partition metadata or topic lookup request, it sometimes replies with the wrong command type. On some failures it replies with nothing, or loses the client's request flags.

  • Failed backend metadata request. The client gets a LOOKUP_RESPONSE instead of a PARTITIONED_METADATA_RESPONSE. The Java and C++ clients keep both request types in one pending map, so they cope. The Go client reports "no partitioned metadata … in lookup response" and loses the broker's error code.
  • PIP-344 auto-creation flag lost. The proxy reads metadata_auto_creation_enabled inside the getConnection().thenAccept(...) callback. When the backend connection isn't ready yet, PulsarDecoder has already cleared the reused command, so the flag reads as its default true. The broker may then create partitioned metadata that the client asked it not to create.
  • Discovery and broker URL failures. These reply with a generic ERROR for both request types. The C++ client's handleError only looks up producer, consumer, last-message-id and topic-list requests. A metadata request or lookup answered this way waits until its operation timeout.
  • Missing broker service URL. If the discovered broker has no URL for the scheme the proxy uses (TLS or not), the proxy writes nothing at all, and every client waits.
  • Broker URL with no port. InetSocketAddress.createUnresolved throws, and the client connection is closed. A lookup redirect to such a URL, or to a null URL, throws inside the backend response callback. The lookup then gets no response, and the backend connection is never released.

Modifications

  • Partition metadata failures at every stage get a PARTITIONED_METADATA_RESPONSE that keeps the client request id, the error code and the message. This covers discovery, broker URL, connection, backend request, and failures thrown synchronously.
  • The auto-creation flag is captured before getConnection is called.
  • Error mapping for metadata failures:
    • timeouts, disconnects and closed connections map to ServiceNotReady;
    • other PulsarClientExceptions map through ClientCnx.revertClientExToErrorCode;
    • anything else maps to ServiceNotReady at the connection stage and to UnknownError after it.
    • Wrapping CompletionException/ExecutionExceptions are unwrapped first. Any other exception still gets a response.
  • The backend connection is released before the response is written, even when the backend request fails synchronously.
  • getBrokerServiceUrl and getAddr take an error callback, so each request type answers with its own failure response.
    • They reject a blank broker URL with ServiceNotReady, and a URL with no host or port with MetadataError.
    • Lookups now use these helpers too, including for redirects.
    • Schema and topic-list requests keep their generic ERROR response.

No new commands or fields are added. Every response uses an existing command with its existing schema.

Verifying this change

LookupProxyHandlerTest is a new deterministic unit test built on an EmbeddedChannel and a mocked connection pool. It covers:

  • the type, request id, error code and message of each response;
  • exactly one response per request;
  • release of the backend connection;
  • the auto-creation flag after the decoder clears the request;
  • discovery and broker URL failures, for both metadata requests and lookups;
  • redirects to invalid URLs.

Without the fix, the tests fail on the LOOKUP_RESPONSE/ERROR command types, on missing responses, and on the forwarded flag.

./gradlew :pulsar-proxy:test --tests 'org.apache.pulsar.proxy.server.LookupProxyHandlerTest' \
    --tests 'org.apache.pulsar.proxy.server.ProxyTest.testGetPartitionedMetadataErrorCode' quickCheck

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

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol (response command types on failure paths only; no new commands or fields)
  • 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
@void-ptr974
[fix][proxy] Return partition metadata responses for failed backend m…
7012eb7
…etadata requests

Use the partition metadata error response when a backend metadata request
fails, preserving the client request ID, error code, and error message.

Add protocol regression tests for metadata errors, successful responses,
and connection failures, including immediate and delayed failures.

Assisted-by: OpenAI Codex
lhotari
lhotari reviewed Oct 13, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

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.

Thanks for tracking this down and for the thorough tests.

The one-line change at LookupProxyHandler.java:282 is correct. A failed backend metadata request now gets a PARTITIONED_METADATA_RESPONSE with Failed, the error code, the message and the client request id. The connection is still released, and exactly one response is written. The tests are deterministic and would fail on the old LOOKUP_RESPONSE.

While tracing the failure paths I found one real bug in the same method. It was there before this PR, but the new test cannot see it. See the inline comment on the test. I think it is worth fixing here, since it is a small change and the test already asserts the flag. A follow-up is fine too.

Smaller things, none of which block this PR:

  • Backend timeouts and disconnects map to UnknownError through revertClientExToErrorCode. The connection-failure path sends ServiceNotReady for the same kind of condition.
  • On the connection-failure path ex is always a CompletionException. Authentication and authorization errors therefore end up as ServiceNotReady, and the message carries a class-name prefix. The test at LookupProxyHandlerTest.java:164-175 pins that behaviour.
  • The assertions inside the doAnswer run inside thenAccept. A failure there is swallowed and shows up as a confusing ServiceNotReady mismatch. Capturing the decoded command in a field and asserting from the test thread would give a clearer failure.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/LookupProxyHandlerTest.java Resolved

Uh oh!

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

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.

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.

@void-ptr974
[improve][proxy] Move metadata lookup assertions to the test thread
bc6d926
Assisted-by: Codex
@void-ptr974

void-ptr974 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. I’ve updated the tests to capture the forwarded request and run the assertions on the test thread, as suggested.

All reactions

Sorry, something went wrong.

Uh oh!

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

lhotari
lhotari reviewed Oct 14, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

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.

Thanks for the update. The new commit only changes the test: the assertions now run on the test thread, and the forwarded buffer is copied and released correctly. I found no problems in that change.

The auto-creation flag point is still open. LookupProxyHandler.java:273-274 still reads the flag inside the thenAccept lambda, and the test still does not clear the request before completing the connection. That is the one point I would like fixed in this PR. The other two threads are optional follow-ups.

Sorry, something went wrong.

Uh oh!

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

All reactions
void-ptr974 and others added 3 commits October 14, 2026 21:38
@void-ptr974
[fix][proxy] Complete partition metadata failure handling
2737e70
Preserve decoded request flags across asynchronous connection acquisition, return partition metadata responses for discovery and address failures, and map wrapped backend errors without losing the response or connection release.

Keep connection-stage failure defaults and the generic response types used by other requests. Cover request clearing, error mapping, invalid addresses, disconnect cleanup, and response write failures with deterministic tests.

Assisted-by: Codex
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/adopt-26607-…
a092da0
…proxy-partition-metadata-errors

# Conflicts:
#	pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/LookupProxyHandler.java
@merlimat
[fix][proxy] Answer failed topic lookups with a lookup response
a496a30
A topic lookup that failed before reaching a broker was answered with a
generic ERROR command when discovery failed or found no broker service
URL. The C++ client only matches an ERROR against its producer, consumer,
last-message-id and topic-list requests, so the lookup waited for its
operation timeout.

A redirect to a broker URL without a port, or without the URL the proxy
uses, threw inside the backend response callback. The client got no
response and the backend connection was not released.

Use the partition metadata path's helpers for lookups: discovery and
broker URL failures are answered with a failed LOOKUP_RESPONSE, and a
blank broker URL is rejected with ServiceNotReady.
@merlimat merlimat changed the title [fix][proxy] Return partition metadata responses for failed backend metadata requests [fix][proxy] Answer failed partition metadata and lookup requests with their own response type Oct 22, 2026
@merlimat

merlimat commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@void-ptr974 thanks for this, and for working through all of @lhotari's review points. I'm adopting the PR as part of the open-PR backlog triage, so it can land while master is still close. I pushed two commits to your branch:

  • A merge of current master. The only conflict was an import added by [fix][broker] Fix topic listing memory limit enforcement #26945.

  • The same fix for topic lookups. handleLookup had the same early-failure gap:

    • Discovery or missing-URL failures replied with a generic ERROR, which the C++ client doesn't match against a pending lookup.
    • A redirect to a broker URL with no port, or to a null URL, threw inside the backend callback. The lookup got no response, and the backend connection was never released.

    Lookups now use your getBrokerServiceUrl/getAddr callbacks with a failed LOOKUP_RESPONSE. The commit adds 11 LookupProxyHandlerTest cases, and all of them fail without the fix.

I also rewrote the description to cover the auto-creation flag fix and the early-failure paths, since the title only named the first one. @lhotari, the flag point you raised is fixed in 2737e70, as discussed in your thread.

All reactions

Sorry, something went wrong.

Uh oh!

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

merlimat
merlimat approved these changes Oct 22, 2026
View reviewed changes
@merlimat
merlimat merged commit c019a2d into apache:master Oct 22, 2026
82 of 85 checks passed

Uh oh!

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

@lhotari lhotari mentioned this pull request Oct 22, 2026
[fix][proxy] Copy GetTopicsOfNamespace properties before the broker connection completes #27055
Merged
11 tasks
@lhotari lhotari added release/4.2.6 release/4.0.15 labels Oct 22, 2026
lhotari pushed a commit that referenced this pull request Oct 23, 2026
@void-ptr974 @merlimat @lhotari
[fix][proxy] Answer failed partition metadata and lookup requests wit…
7f5e884
…h their own response type (#26607)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit c019a2d)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels 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 cherry-picked/branch-4.0 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@void-ptr974 @merlimat @lhotari
[fix][proxy] Answer failed partition metadata and lookup requests wit…
d9a256f
…h their own response type (apache#26607)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit c019a2d)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@void-ptr974 @merlimat @lhotari
[fix][proxy] Answer failed partition metadata and lookup requests wit…
e8e574c
…h their own response type (apache#26607)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit c019a2d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lhotari lhotari lhotari left review comments
@merlimat merlimat merlimat 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 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

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