Skip to content

[fix][test] Fix flaky ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail - #25497

Merged
merlimat merged 2 commits into
apache:masterfrom
lhotari:fix-flaky-ServerCnxTest-testCreateProducerTimeout
Apr 8, 2026
Merged

[fix][test] Fix flaky ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail#25497
merlimat merged 2 commits into
apache:masterfrom
lhotari:fix-flaky-ServerCnxTest-testCreateProducerTimeout

Conversation

@lhotari

@lhotari lhotari commented Apr 8, 2026

Copy link
Copy Markdown
Member

Fixes #25249

Motivation

Fix flaky ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail that fails intermittently on master.

Root cause: When channel.writeInbound(createProducer1) was called, the producer registration in the producers map happened asynchronously in a thenApplyAsync callback on ctx.executor(). In EmbeddedChannel, these callbacks only execute when channel.runPendingTasks() is called. Without draining pending tasks before the close command, handleCloseProducer could 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 on putIfAbsent for the same producerId, causing one to fail with CommandError.

Modifications

Added channel.runPendingTasks() after the first writeInbound(createProducer1) to ensure the async callback runs and registers the producer in the producers map before the close command is processed.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail. Verified with invocationCount=10 locally (10/10 passes).

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
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

…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
merlimat merged commit 7ce8a8c into apache:master Apr 8, 2026
117 of 122 checks passed
lhotari added a commit that referenced this pull request Apr 21, 2026
…teSameNamedProducerShouldFail (#25497)

(cherry picked from commit 7ce8a8c)
lhotari added a commit that referenced this pull request Apr 21, 2026
…teSameNamedProducerShouldFail (#25497)

(cherry picked from commit 7ce8a8c)
lhotari added a commit that referenced this pull request Apr 21, 2026
…teSameNamedProducerShouldFail (#25497)

(cherry picked from commit 7ce8a8c)
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)
@lhotari lhotari added this to the 5.0.0-M1 milestone Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky-test: ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail

2 participants