test: poll for port release in TcpServerTest to fix flake#166
Open
kinyoklion wants to merge 11 commits into
Open
test: poll for port release in TcpServerTest to fix flake#166kinyoklion wants to merge 11 commits into
kinyoklion wants to merge 11 commits into
Conversation
After TcpServer.close(), there can be a brief OS-level delay before the port is fully released. Replace the immediate assertion with a polling helper that retries for up to 1 second. Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
joker23
approved these changes
May 27, 2026
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.
Requirements
Related issues
Fixes a flaky
TcpServerTest.listensOnSpecificPorttest observed in CI.Describe the solution you've provided
After
TcpServer.close(), there can be a brief OS-level delay before the port is fully released. The test was immediately checkingdoesPortHaveListener()which could return true in that window.Replaced the immediate
assertFalsecalls with a polling helper (assertPortReleased) that retries for up to 1 second before failing. Applied to bothlistensOnSpecificPortandlistensOnAnyAvailablePortfor consistency.Describe alternatives you've considered
Thread.sleep()before the assertion — less robust and adds unnecessary delay in the common case.TcpServer.close()to join the accept thread — would be an application code change rather than a test fix.Additional context
The flake was observed on
ubuntu-latestwith Java 19 during CI.Link to Devin session: https://app.devin.ai/sessions/89320790abd2401e90b44eb0fcfb66be
Requested by: @kinyoklion
Note
Low Risk
Test-only timing change in shared test helpers; no production or security impact.
Overview
TcpServerTest no longer asserts that a port is free the instant
TcpServercloses. BothlistensOnAnyAvailablePortandlistensOnSpecificPortnow call a newassertPortReleasedhelper that pollsdoesPortHaveListenerfor up to one second (50 ms between attempts) before failing with the same message as before.This addresses CI flakes where the OS can still report a listener briefly after close.
Reviewed by Cursor Bugbot for commit 9d42e36. Bugbot is set up for automated code reviews on this repo. Configure here.