From c6533392f6f20c4b7a3e68edac983ab4dc4a3f59 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Wed, 11 Nov 2026 15:28:03 +0100 Subject: [PATCH] socket: define Socket::SO_OOBINLINE, which MRI has and this table did not MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ruby/spec's FTP fixture sets it inside the Thread that serves the connection (library/net-ftp/fixtures/server.rb:25), where an undefined name raises NameError and kills that thread with nothing to show for it at the other end of the socket. ⛔ IT IS NOT THE CAUSE OF #916, and the comment I first wrote here said it was. Adding the constant left the sweep BYTE-IDENTICAL: 39 files still killed by the clock, 459 / 17, -442. The fixture's thread never reaches this line -- it is still parked in TCPServer#accept while a client is connected and waiting. A fix that does not move the measurement is not a fix, whatever its author expected, and the comment now records that rather than the guess. The value is BSD/darwin's like its neighbours, and is never passed to the kernel: BasicSocket#setsockopt is a no-op on a connected stream and Socket#setsockopt stores the (level, optname) pair for #getsockopt to read back. The numbers here are symbolic -- which is why a darwin value is not a portability bug today, and why that whole table deserves an audit it has not had. Refs #916 Co-Authored-By: Claude Opus 5 --- internal/vm/socket.go | 24 ++++++++++++++++++++++++ internal/vm/socket_raw_test.go | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/internal/vm/socket.go b/internal/vm/socket.go index a2529d47..1b6a3974 100644 --- a/internal/vm/socket.go +++ b/internal/vm/socket.go @@ -226,6 +226,30 @@ func (vm *VM) registerSocketClass(basic *RClass) { "IPPROTO_TCP": 6, "IPPROTO_UDP": 17, "IPPROTO_IP": 0, "SOL_SOCKET": 0xffff, "SO_REUSEADDR": 4, "SO_KEEPALIVE": 8, "SO_BROADCAST": 32, "SO_RCVBUF": 0x1002, "SO_SNDBUF": 0x1001, "TCP_NODELAY": 1, + // SO_OOBINLINE, which MRI defines and this table did not. ruby/spec's FTP + // fixture server calls + // + // @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1) + // + // (library/net-ftp/fixtures/server.rb:25) inside the Thread that serves + // the connection, so an undefined constant raises NameError there and + // kills that thread silently. + // + // ⛔ IT IS NOT, HOWEVER, THE CAUSE OF #916, and this comment said it was + // until the measurement refuted it. Adding the constant left the sweep + // byte-identical -- 39 files still killed by the clock, 459/17, -442 -- + // because the fixture's thread never reaches this line: it is still + // parked in TCPServer#accept while a client is connected and waiting. + // A fix that does not move the measurement is not a fix, whatever its + // author expected. + // + // The value is BSD/darwin's, like its neighbours above, and is never + // passed to the kernel: BasicSocket#setsockopt is a no-op on a connected + // stream and Socket#setsockopt stores the (level, optname) pair in a map + // for #getsockopt to read back. The numbers here are symbolic, which is + // why a darwin value is not a portability bug today -- and why that + // whole table deserves an audit it has not had. + "SO_OOBINLINE": 0x0100, // getnameinfo flags (BSD numbering; the values only matter relative to the // bitmask tests in Socket.getnameinfo). "NI_NUMERICHOST": 2, "NI_NUMERICSERV": 8, "NI_NOFQDN": 1, "NI_NAMEREQD": 4, "NI_DGRAM": 16, diff --git a/internal/vm/socket_raw_test.go b/internal/vm/socket_raw_test.go index 0e250347..4cd69beb 100644 --- a/internal/vm/socket_raw_test.go +++ b/internal/vm/socket_raw_test.go @@ -195,6 +195,16 @@ s.close`, "0\n1\n0"}, "false\ntrue"}, // Symbol / String domain and type names are accepted. {`s=Socket.new(:INET, :STREAM); p s.closed?; s.close`, "false"}, + // ⛔ A CONSTANT MRI DEFINES AND THIS TABLE DID NOT. ruby/spec's FTP + // fixture sets SO_OOBINLINE inside the Thread that serves the + // connection, so an undefined name raises NameError there and kills + // that thread with nothing to show for it at the other end of the + // socket. A missing constant is a NameError wherever it is read; it is + // only SILENT when it is read in a thread nobody joins. + {`s=Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) +p s.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1) +p s.getsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE) +s.close`, "0\n1"}, } for _, c := range cases { if got := runSrc(t, "require \"socket\"\n"+c.src); got != c.want {