Skip to content

[Test] Pick spec ports outside the ephemeral port range - #291

Merged
jsvd merged 1 commit into
logstash-plugins:mainfrom
jsvd:fix-flaky-port-allocation-spec
Nov 4, 2026
Merged

jsvd merged 1 commit into
logstash-plugins:mainfrom
jsvd:fix-flaky-port-allocation-spec

Conversation

@jsvd

@jsvd jsvd commented Oct 21, 2026

Copy link
Copy Markdown
Member

What does this PR do?

find_available_port bound port 0, read the assigned port and released it; the plugin bound it later. That port is in the kernel's ephemeral range, so in between it could be handed to another socket (could not bind to 0.0.0.0:41141; Address already in use).

The spec helper now picks a random port in 1024..32767 (below both the Linux and macOS ephemeral ranges) and retries until one binds. Spec-only change.

How to test this PR locally

./gradlew vendor && bundle exec rspec. Not reproducible on macOS (different ephemeral range); the PROXY v1 spec and other pipeline specs pass consistently. Two specs (:413, :895) fail locally on macOS on unmodified main too and are unrelated.

Related issues

Scheduled CI on main (9.current): https://github.com/logstash-plugins/logstash-input-tcp/actions/runs/37903569094
Note: #238 also touches find_available_port and may conflict textually.

🤖 Generated with Claude Code

find_available_port bound to port 0, read the kernel-assigned ephemeral
port and released it before the plugin bound to it. In the meantime the
kernel could hand the same ephemeral port to another socket, making the
plugin fail with "could not bind to 0.0.0.0:<port>; Address already in
use" (seen in scheduled CI on PROXY protocol v1 spec, port 41141).

Pick a random port below the Linux/macOS ephemeral ranges instead,
retrying until one is bindable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Changelog and Version Management

No changelog or version changes detected. You can either update them manually or use a comment command to update them automatically on merge:

/pr_prepare release:<patch|minor|major> — bump version + update changelog
/pr_prepare changelog:add — changelog entry only (no version bump)

/pr_prepare release:patch
- Add the changelog entry here
  - (Additional details can be provided in multiple lines, respecting markdown formatting)

Omit the entry line to use the PR title. If multiple commands are posted, the last one wins.

@jsvd
jsvd marked this pull request as ready for review November 4, 2026 11:50
@jsvd
jsvd merged commit 94b6bb2 into logstash-plugins:main Nov 4, 2026
13 checks passed
@jsvd
jsvd deleted the fix-flaky-port-allocation-spec branch November 4, 2026 11:53
jsvd added a commit that referenced this pull request Nov 4, 2026
get_port picked a random port in 10000..65535, checked it was free and
released it before the plugin bound it. Ports above 32767 are in the
kernel's ephemeral range, so in between another socket could be handed
the same port ("could not bind ... Address already in use").

Pick from 10000..32767 instead, below both the Linux (32768-60999) and
macOS (49152-65535) ephemeral ranges.

Equivalent of the main-branch fix in #291, adapted to 6.x's get_port.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant