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
commented
Sep 16, 2026
•
edited by merlimat
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
…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
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
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
…proxy-partition-metadata-errors
# Conflicts:
# pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/LookupProxyHandler.java
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
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
|
@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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 21, 2026
Reviewers
lhotari
lhotari left review comments
merlimat
merlimat approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
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.
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.
|