Skip to content

[fix][test] Fix flaky BrokerRegistryIntegrationTest port binding race#25463

Open
merlimat wants to merge 1 commit intoapache:masterfrom
merlimat:fix/flaky-BrokerRegistryIntegrationTest
Open

[fix][test] Fix flaky BrokerRegistryIntegrationTest port binding race#25463
merlimat wants to merge 1 commit intoapache:masterfrom
merlimat:fix/flaky-BrokerRegistryIntegrationTest

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

@merlimat merlimat commented Apr 3, 2026

Motivation

BrokerRegistryIntegrationTest.setup is flaky due to a port binding race condition. Ports are allocated at field initialization time via PortManager.nextFreePort(), but by the time @BeforeClass runs, those ports may have been reused by another test class.

Stack trace

Gradle suite > Gradle test > BrokerRegistryIntegrationTest > setup FAILED
    java.io.IOException: java.net.BindException: Address already in use
        at LocalBookkeeperEnsemble.runZookeeper(LocalBookkeeperEnsemble.java:219)
        at LocalBookkeeperEnsemble.start(LocalBookkeeperEnsemble.java:420)
        at BrokerRegistryIntegrationTest.setup(BrokerRegistryIntegrationTest.java:52)
        Caused by: java.net.BindException: Address already in use

BrokerRegistryIntegrationTest.cleanup FAILED
    java.lang.NullPointerException at BrokerRegistryIntegrationTest.java:71

Modifications

  • Move LocalBookkeeperEnsemble creation from field initialization to @BeforeClass
  • Use port 0 for automatic OS port allocation instead of PortManager.nextFreePort()
  • Add null guard for bk in cleanup to handle setup failures gracefully

Documentation

  • doc-not-needed

Move port allocation and LocalBookkeeperEnsemble creation from field
initialization to @BeforeClass to avoid port reuse. Use port 0 to let
the OS automatically allocate free ports. Add null guard for bk in
cleanup to handle setup failures gracefully.
@apache apache deleted a comment from github-actions bot Apr 3, 2026
@github-actions github-actions bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/test 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