[fix][broker] Prevent timed-out producer creation from racing with retry#25460
Merged
merlimat merged 1 commit intoapache:masterfrom Apr 3, 2026
Conversation
5 tasks
merlimat
approved these changes
Apr 3, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
https://github.com/Denovo1998/pulsar/actions/runs/23939130687/job/69821936858
org.apache.pulsar.broker.service.ServerCnxTest#testCreateProducerTimeout
Motivation
PR #25352 changed several
ServerCnxproducer creation callbacks to run asynchronously onctx.executor(). That change fixed one class of async callback races, but it also introduced a new race in the client-timeout / retry path for producer creation.When a client-side
createProducerrequest times out, the client can immediately send aCloseProducerfollowed by anothercreateProducerrequest with the same producer id and producer name. AfterhandleCloseProducer()completes the firstproducerFutureexceptionally, the delayed async callbacks introduced by #25352 can still continue and eventually invokebuildProducerAndAddTopic()for that stale request.Before this change, the stale request could still call
topic.addProducer()and temporarily register a producer on the topic. If the retry request reachedtopic.addProducer()in the same window, it could fail withNamingException: Producer with name ... is already connected, even though the original request had already timed out on the client side.timed-out create #1retry create #2handleProducer()storesproducerFuturefor producer id1handleCloseProducer()completes the firstproducerFutureexceptionallyhandleProducer()receives a retry with the same producer id and producer namebuildProducerAndAddTopic()buildProducerAndAddTopic()ctx.executor().topic.addProducer()AbstractTopic.producerseven though the client had already timed out.topic.addProducer()topic.addProducer()fails withNamingExceptionProducer with name ... is already connected.producerFuturewas already failed and clears itselfModifications
ServerCnx.buildProducerAndAddTopic()to skip producer construction and topic registration when the correspondingproducerFuturehas already been completed exceptionally by the timeout/close path.topic.addProducer()is reached.ServerCnxTest.testCreateProducerTimeoutandServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail.Verifying this change
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: Denovo1998#26