[fix][test] Fix flaky ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail - #25497
Merged
merlimat merged 2 commits intoApr 8, 2026
Conversation
…teSameNamedProducerShouldFail The test was flaky because of a race condition between producer registration and the close command. In EmbeddedChannel, the producer registration happens in a thenApplyAsync callback that only runs when pending tasks are drained. Without explicitly running pending tasks after writeInbound(createProducer1), the close command could not find the producer in the producers map, causing it to skip cancellation. This led to both producer creation requests racing to register in the map, with one failing with CommandError instead of the expected CommandProducerSuccess. The fix adds channel.runPendingTasks() after the first createProducer command to ensure the producer is registered before the close command is processed. Fixes apache#25249
merlimat
approved these changes
Apr 8, 2026
srinath-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Apr 23, 2026
…teSameNamedProducerShouldFail (apache#25497) (cherry picked from commit 7ce8a8c) (cherry picked from commit 7d10a66)
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
May 27, 2026
…teSameNamedProducerShouldFail (apache#25497) (cherry picked from commit 7ce8a8c)
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.
Fixes #25249
Motivation
Fix flaky
ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFailthat fails intermittently on master.Root cause: When
channel.writeInbound(createProducer1)was called, the producer registration in theproducersmap happened asynchronously in athenApplyAsynccallback onctx.executor(). InEmbeddedChannel, these callbacks only execute whenchannel.runPendingTasks()is called. Without draining pending tasks before the close command,handleCloseProducercould not find the producer in the map, took the "producer not registered" path, and didn't cancel anything. When both producer creation tasks later ran, they raced onputIfAbsentfor the sameproducerId, causing one to fail withCommandError.Modifications
Added
channel.runPendingTasks()after the firstwriteInbound(createProducer1)to ensure the async callback runs and registers the producer in theproducersmap before the close command is processed.Verifying this change
This change is already covered by existing tests, such as
ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail. Verified withinvocationCount=10locally (10/10 passes).Does this pull request potentially affect one of the following parts: