Skip to content

[fix][broker] Fix race condition in producer creation that causes flaky tests#25464

Closed
merlimat wants to merge 1 commit intoapache:masterfrom
merlimat:fix/flaky-ServerCnx-producer-timeout
Closed

[fix][broker] Fix race condition in producer creation that causes flaky tests#25464
merlimat wants to merge 1 commit intoapache:masterfrom
merlimat:fix/flaky-ServerCnx-producer-timeout

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

@merlimat merlimat commented Apr 3, 2026

Motivation

ServerCnxTest.testCreateProducerTimeout and testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail are flaky due to a race condition in the producer creation async chain.

When a producer creation times out, the close command completes the producerFuture before buildProducerAndAddTopic runs. The producer still gets added to the topic briefly via topic.addProducer(), blocking a subsequent producer with the same name from being created.

Stack traces

ServerCnxTest > testCreateProducerTimeout FAILED
    java.lang.AssertionError at ServerCnxTest.java:2094

ServerCnxTest > testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail FAILED
    java.lang.AssertionError: expected [class CommandProducerSuccess] but found [class CommandError]
        at ServerCnxTest.testCreateProducerTimeoutThenCreateSameNamedProducerShouldFail(ServerCnxTest.java:2153)

Modifications

Add a producerFuture.isDone() check in buildProducerAndAddTopic before calling topic.addProducer(). If the future was already completed (e.g. by a close/timeout), clean up and return early instead of registering the producer on the topic.

Documentation

  • doc-not-needed

…ky tests

When a producer creation times out, the close command completes the
producerFuture before buildProducerAndAddTopic runs. The producer still
gets added to the topic briefly, blocking a subsequent producer with
the same name. Fix by checking producerFuture.isDone() before calling
topic.addProducer().
@github-actions github-actions bot added doc-label-missing doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Apr 3, 2026
@apache apache deleted a comment from github-actions bot Apr 3, 2026
@merlimat
Copy link
Copy Markdown
Contributor Author

merlimat commented Apr 3, 2026

Fixed in #25460

@merlimat merlimat closed this Apr 3, 2026
@merlimat merlimat deleted the fix/flaky-ServerCnx-producer-timeout branch April 3, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant