[fix][broker] Fix lookup permit leak when namespace policy reads fail - #26606
void-ptr974 wants to merge 3 commits into
Conversation
Assisted-by: Codex
| try { | ||
| if (ex != null) { | ||
| Throwable actEx = FutureUtil.unwrapCompletionException(ex); | ||
| if (authorizationFuture.isCompletedExceptionally()) { |
There was a problem hiding this comment.
This approach works with the current chain, but I'm concerned that error mapping now depends on inspecting the authorizationFuture and autoCreationFuture to infer which stage failed. This makes the terminal handler tightly coupled to the chain's exact structure. Could we explicitly carry the stage or result—or map each stage’s failure before reaching the terminal handler—instead? Doing so would make it safer to extend later.
There was a problem hiding this comment.
Addressed in ace4156. Each stage now maps its own failures in handle, and all branches are composed into the request chain. The terminal callback releases the permit and logs unexpected callback failures. This removes the intermediate future-state checks while preserving the existing error mappings and response send paths.
| } finally { | ||
| try { | ||
| if (topicExistsInfo != null) { | ||
| topicExistsInfo.recycle(); |
There was a problem hiding this comment.
Can we capture or log a recycle() failure here? The permit is still released correctly. However, the future returned by whenComplete is ignored, and if recycle() throws an exception, it ends up in an unobserved dependent future, effectively disappearing. Since the new test explicitly exercises this scenario, it would be useful to make the cleanup failure visible without altering the response or release behavior.
try {
if (topicExistsInfo != null) {
topicExistsInfo.recycle();
}
} catch (Throwable cleanupError) {
log.error()
.attr("topic", topicName)
.exception(cleanupError)
.log("Failed to recycle partition metadata lookup result");
} finally {
lookupSemaphore.release();
}There was a problem hiding this comment.
Addressed in ace4156. TopicExistsInfo is now recycled in the lookup callback’s finally block. A cleanup exception propagates through the composed chain to the terminal callback, which releases the permit and logs the exception without attempting another response. The existing cleanup-failure test now also verifies that the exception is logged once.
Compose authorization, policy checks, and metadata queries while handling business failures within their originating stages. Recycle topic existence results locally, release lookup permits once after the request completes, and log unexpected callback failures without attempting another response. Cover delayed stage completion, existing-topic results, error mappings, and cleanup observability. Validation: 46 scoped tests and quickCheck pass with retries disabled. Policy failure regressions fail on the pre-fix implementation and pass with this change. Assisted-by: Codex
|
Updated in ace4156 to address both review comments. Error and response handling now stays within each stage, lookup results are recycled locally, and permit release remains centralized. Added tests for delayed authorization/policy/lookup completion, result recycling, and error mappings across both lookup paths. Local validation passed 46 scoped test cases and |
Retain both PulsarClientException and Schema imports in ServerCnxTest. Assisted-by: Codex
Motivation
Partition metadata lookup starts
isAllowAutoTopicCreationAsyncinside a callback without composing its future into the request chain. If the namespace policy read fails asynchronously, the broker sends no error response and never releases the acquired lookup permit. Repeated failures consume the permits shared by broker lookup and partition metadata lookup, leaving clients waiting for timeouts and subsequent requests rejected.Modifications
handlewhile preserving the existing error mappings and response send paths.TopicExistsInfoin the lookup callback'sfinallyblock. Release the lookup permit once in the terminal callback and log unexpected callback failures without attempting another response.Verifying this change
This change added tests and can be verified as follows:
ServerCnxTestand 20 inGetPartitionMetadataTest) andquickCheck, with retries disabled.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes