Skip to content

test: poll for port release in TcpServerTest to fix flake#166

Open
kinyoklion wants to merge 11 commits into
mainfrom
devin/1779836685-fix-tcp-server-test-flake
Open

test: poll for port release in TcpServerTest to fix flake#166
kinyoklion wants to merge 11 commits into
mainfrom
devin/1779836685-fix-tcp-server-test-flake

Conversation

@kinyoklion
Copy link
Copy Markdown
Member

@kinyoklion kinyoklion commented May 26, 2026

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Fixes a flaky TcpServerTest.listensOnSpecificPort test 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 checking doesPortHaveListener() which could return true in that window.

Replaced the immediate assertFalse calls with a polling helper (assertPortReleased) that retries for up to 1 second before failing. Applied to both listensOnSpecificPort and listensOnAnyAvailablePort for consistency.

Describe alternatives you've considered

  • Adding a fixed Thread.sleep() before the assertion — less robust and adds unnecessary delay in the common case.
  • Modifying 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-latest with 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 TcpServer closes. Both listensOnAnyAvailablePort and listensOnSpecificPort now call a new assertPortReleased helper that polls doesPortHaveListener for 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.

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>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration Bot added the devin-pr Label for PR's created using devin. label May 26, 2026
@kinyoklion kinyoklion marked this pull request as ready for review May 26, 2026 23:08
@kinyoklion kinyoklion requested a review from a team as a code owner May 26, 2026 23:08
devin-ai-integration Bot and others added 10 commits May 26, 2026 23:09
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin-pr Label for PR's created using devin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants