From fd65a1247076a680e8a8aa9b638e609f9d317b1f Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Wed, 21 Oct 2026 14:13:47 +0900 Subject: [PATCH] Fix flaky TCPServer functional specs that listen on localhost 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 --- spec/tcp_server_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/tcp_server_spec.rb b/spec/tcp_server_spec.rb index 6790980..933a8a9 100644 --- a/spec/tcp_server_spec.rb +++ b/spec/tcp_server_spec.rb @@ -175,9 +175,9 @@ def on_connect it "connected socket called on_connect" do begin connected = false - server = Cool.io::TCPServer.new("localhost", port, ServerOnConnect, proc { connected = true }) + server = Cool.io::TCPServer.new(HOST, port, ServerOnConnect, proc { connected = true }) loop.attach server - s = TCPSocket.open("localhost", port) + s = TCPSocket.open(HOST, port) loop.run_once s.close expect(connected).to eq true @@ -201,9 +201,9 @@ def on_close it "closed socket called on_close" do begin closed = false - server = Cool.io::TCPServer.new("localhost", port, ServerOnConnect, proc { closed = true }) + server = Cool.io::TCPServer.new(HOST, port, ServerOnConnect, proc { closed = true }) loop.attach server - s = TCPSocket.open("localhost", port) + s = TCPSocket.open(HOST, port) loop.run_once s.close loop.run_once @@ -229,10 +229,10 @@ def on_read(data) it "server socket received data" do begin data = "aaa" - server = Cool.io::TCPServer.new("localhost", port, Echo, proc { |d| data = d }) + server = Cool.io::TCPServer.new(HOST, port, Echo, proc { |d| data = d }) loop.attach server thread = Thread.new { loop.run } - s = TCPSocket.open("localhost", port) + s = TCPSocket.open(HOST, port) s.write "zzz" sleep 0.1 expect(data).to eq "zzz"