Skip to content

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

Merged
nodece merged 1 commit into
apache:masterfrom
merlimat:fix/flaky-BrokerRegistryIntegrationTest
Apr 7, 2026
Merged

[fix][test] Fix flaky BrokerRegistryIntegrationTest port binding race#25463
nodece merged 1 commit into
apache:masterfrom
merlimat:fix/flaky-BrokerRegistryIntegrationTest

Conversation

@merlimat

@merlimat merlimat commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

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
@nodece
nodece merged commit aaf2def into apache:master Apr 7, 2026
81 of 86 checks passed
@lhotari lhotari added this to the 4.3.0 milestone Apr 22, 2026
lhotari pushed a commit that referenced this pull request Apr 22, 2026
lhotari pushed a commit that referenced this pull request Apr 22, 2026
lhotari pushed a commit that referenced this pull request Apr 22, 2026
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 23, 2026
nodece pushed a commit to ascentstream/pulsar that referenced this pull request May 27, 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.

4 participants