Skip to content

Fix flaky TCPServer functional specs that listen on localhost - #127

Merged
Watson1978 merged 1 commit into
socketry:mainfrom
Watson1978:fix-tcp-server-spec-localhost
Oct 21, 2026
Merged

Watson1978 merged 1 commit into
socketry:mainfrom
Watson1978:fix-tcp-server-spec-localhost

Conversation

@Watson1978

@Watson1978 Watson1978 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

The TCPServer functional examples listen and connect on "localhost", which resolves to ::1 first, while unused_port only checks IPv4. Those examples only detach their servers, so a ::1 listener can stay open on a port that unused_port returns again. The next server then falls back to 127.0.0.1, the client connects to the stale ::1 listener, and the example fails after about 60 seconds, as in this job. This uses 127.0.0.1 on both sides, as the other examples in the file do.

Failures:

  1) Coolio::TCPServer functionaltest #on_read server socket received data
     Failure/Error: expect(data).to eq "zzz"

       expected: "zzz"
            got: "aaa"

       (compared using ==)
     # ./vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.7/lib/rspec/support.rb:110:in `block in <module:Support>'
     # ./vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.7/lib/rspec/support.rb:119:in `notify_failure'
...

Types of Changes

  • Maintenance.

Contribution

🤖 Generated with Claude Code

unused_port only checks IPv4, but a server on "localhost" binds ::1
first. These examples only detach their servers, so a ::1 listener can
stay open on a port that unused_port returns again. The next server
then falls back to 127.0.0.1, while the client still connects to the
stale ::1 listener and the data never arrives. Use 127.0.0.1 on both
sides, as the other examples in this file do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Watson1978
Watson1978 merged commit a33d647 into socketry:main Oct 21, 2026
15 checks passed
@Watson1978
Watson1978 deleted the fix-tcp-server-spec-localhost branch October 21, 2026 05:17
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