Repository navigation
socket: the three open doors #931 named and nothing wired - #939
Merged
Merged
Conversation
#932 gave `open` MRI's block semantics on TCPSocket, TCPServer and Socket. #931's "shape of the fix" named the rest of the family in the same breath — UNIXSocket, UDPSocket, UNIXServer — and nothing carried it out. Those three went on aliasing `open` straight to `new`, so a block handed to them was DISCARDED WITHOUT A WORD: no error, no warning, a body that simply never ran. Three of six doors wired is this week's recurring shape, and the reason it keeps recurring is that the wrapper is shared while the WIRING is per class. | class | was | now | | --- | --- | --- | | `UDPSocket` (socket_udp.go) | `native: newFn` | `socketOpenWithBlock(udp, newFn)` | | `UNIXSocket` (socket_unix.go) | `native: newSock` | `socketOpenWithBlock(sock, newSock)` | | `UNIXServer` (socket_unix.go) | `native: newSrv` | `socketOpenWithBlock(srv, newSrv)` | ## Checked before writing: the wrapper could have been a no-op here `socketOpenWithBlock` closes through `cls.methods["close"]` — the class's OWN method table, not its ancestors. A class whose `close` is inherited would have taken the wrapper and closed nothing, and the fix would have read as done. All three define `close` directly: UNIXSocket through `installStreamIO` (socket.go:480), UNIXServer at socket_unix.go:144, UDPSocket at socket_udp.go:170. That is why the test asserts `closed?` rather than trusting the wrapper. ## ⛔ Each door proved by MUTATION, and each by ASSERTION A test that passes before and after proves nothing, so each wiring was reverted in turn: | reverted | the test said | | --- | --- | | `UDPSocket` | `[:udp, #<UDPSocket>, :block_never_ran]` + `[:udp_raise, false, :block_never_ran]` | | `UNIXSocket` | `[:unixsocket, #<UNIXSocket>, :block_never_ran]` | | `UNIXServer` | `[:unixserver, #<UNIXServer>, :block_never_ran, true]` | Three separate reds, each naming its own door and leaving the other two lines intact — so this is one case per door, not one case that happens to cover one of them. The first draft failed by `NoMethodError: undefined method 'closed?' for nil` instead. That is a panic standing in for an assertion: it detects the regression but does not say what happened. Each case now prints `:block_never_ran` for a variable the block never set, which makes a discarded block a readable diff. ⛔ And the UNIXSocket case deliberately has its server `close` AT ONCE without reading. A server waiting for EOF would, with the door unwired, leave the client open and HANG this test rather than fail it — the exact failure this whole issue is about, reproduced inside its own regression test. ## Two traps recorded in the code rather than worked around - **`t.TempDir()` puts the TEST'S NAME in the path, and `sun_path` is 104 bytes on darwin.** This test's name alone pushed the socket over, and `bind(2)` answers `invalid argument` — which reads as a bug in the code under test. The neighbouring tests fit only because their names are shorter, which is not a property anyone would think to preserve when renaming one. Short `os.MkdirTemp` dir, with the reason in a comment. - A **backtick inside the Ruby source** closes the Go raw string that holds it. The test's Ruby comments say `.new`, not a quoted `new`, for that reason. ## A fourth site, outside the socket family, filed rather than fixed Deriving the population instead of trusting #931's list found `internal/vm/resolv.go:199`: dns.smethods["open"] = dns.smethods["new"] `Resolv::DNS.open` with a block is the same defect. MRI 4.0.7 (`lib/ruby/4.0.0/resolv.rb:301-309`, read on this machine) yields, returns the block's value and closes in an `ensure`. It is NOT fixed here, because rbgo's `Resolv::DNS#close` currently raises `NotImplementedError` (resolv.go:207, in the "needs real DNS sockets" list, where closing a resolver that opened nothing does not belong) — so wiring the block form naively would trade a silent discard for a raise. Two steps, its own change, filed separately. Full `internal/vm` suite green (386 s under a 1-minute load average of 61); `gofmt -l .` silent. Refs #931, #932, #916 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
tannevaled
added a commit
that referenced
this pull request
Nov 16, 2026
#951) * vm: derive the `open` doors instead of listing them, and wire the fourth `Klass.open { |x| … }` yields, closes however the block leaves, and answers with the BLOCK's value. `smethods["open"] = smethods["new"]` gives none of that — `new` has no block parameter, so the block is discarded in silence and the call still looks like it worked. That one line cost #916 its 27 hung library/net-http files. ⛔ AND THE LIST OF DOORS IS WHAT KEPT DRIFTING. #931 wrote the socket doors out in prose and the prose had already lost UNIXServer; #939 re-derived them from the source, fixed three, and found a FOURTH nobody had written down — Resolv::DNS, outside the socket family — which it filed rather than fixed. A hand-written list of doors is the same artefact as any other hand-written list. So TestEveryOpenDoorIsAccountedFor holds none. It parses the package with go/ast, on EVERY platform (go/parser ignores build tags, which is how the windows-only UNIX doors get counted — the prose list missed UNIXServer in exactly such a file), finds all 18 `smethods["open"]` assignments, and compares them to testdata/open-doors.txt BOTH WAYS: a door missing from the table fails, and a row for a door that no longer exists fails too. The ALIAS form is refused outright, because no configuration of it can be correct. Mutation control: putting the alias back prints `⛔ 1 open door(s) are an ALIAS … resolv.go:dns`, naming file and receiver. TestTheOpenDoorClassifierTellsTheShapesApart feeds the four shapes to the classifier directly — without it every assertion would pass against a classifier that answered "block helper" for everything. ## The fourth door, measured against MRI 4.0.7 Resolv::DNS.open { |dns| :from_block } MRI yields, returns :from_block rbgo did NOT yield, returned #<Resolv::DNS…> Resolv::DNS#close MRI nil, and a second close is fine rbgo NotImplementedError, both times Both halves are ONE fix: socketOpenWithBlock closes through the class's own #close, so leaving #close on the NotImplementedError list would have turned every `Resolv::DNS.open { … }` into a NotImplementedError raised from the ensure — a block that now runs, and a program that now fails. Same trap as #948's teardown flush. ⛔ And #close takes NO arguments. The pre-existing TestResolvDNS asserted that `close("x")` raises, and it did — with NotImplementedError, which is the right verdict for the wrong reason: the stub raised for every call, so the test could not tell "close rejects an argument" from "close does nothing at all". A no-op close turned it red, which is the test finally asking its own question. MRI 4.0.7: ArgumentError "wrong number of arguments (given 1, expected 0)", arity 0, `close` → nil. `close` comes off that loop's hand-written list (which mirrored the production one) and is asserted on its MESSAGE and its arity instead. rubydiff against MRI 4.0.7 now AGREES on both witnesses — stdout, stderr and exit status — where it diverged on three rows before. ## What the derivation exposed: #950 Two doors take a block and discard it: Augeas.open (augeas.go:71, shared with Augeas.create) and Images::Image.open (images.go:93), both `_ *Proc`. The other seven inline handlers were read one by one and all honour theirs (File, IO, StringIO, Dir, Net::FTP, SQLite3::Database, bbolt). NOT measured, and it is the whole decision: whether the reference gems accept a block at all. Neither is installed here. Images::Image.open may be CORRECT — ruby-vips and MiniMagick spell this without a block. Listed in the table as unverified, with #950 carrying the command that settles it, so two doors are countable rather than quiet. ⚠ There is no issue to close for the fourth door. "#939 filed it" — which is what its own text and the recurrence ledger both say — meant RECORDED IN PROSE, inside #939: `gh issue list --search "Resolv in:title"` over every state answers `[]`. A door named only in a merged pull request's body is as findable as one named nowhere, which is the same lesson as the prose list it was found by. Refs #931, #916, #939, #950, #948 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * testdata: the Augeas reference was READ, so the row may not say 'recalled' The table said ruby-augeas is 'BELIEVED to yield and close, but that is recalled and not read'. It has now been read, so that sentence was the exact shape it warns against — a dated claim left standing in a file whose only job is to be honest about what is verified. ruby-augeas lib/augeas.rb: def self.open(root = nil, loadpath = nil, flags = NONE, &block) aug = open3(root, loadpath, flags) if block_given? begin rv = yield aug return rv ensure aug.close end else return aug end end Same parameters as rbgo's, and exactly socketOpenWithBlock's contract. So Augeas.open is a CONFIRMED defect, not an open question. Still not fixed here, and the reason is new: rbgo's Augeas has no #close AT ALL (git grep close internal/vm/augeas.go is empty), so the helper would yield without closing and aug.close in Ruby is a NoMethodError. Adding #close means reading go-augeas's handle API, which is its own change. Images::Image.open moves the other way: go-ruby-images' README documents no Ruby Image.open and no block form at all, only the Go-level images.Open(path). It is UNSPECIFIED, not a known defect, and the two rows no longer read as if they were in the same state. Refs #950 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
socket: the three
opendoors #931 named and nothing wired#932 gave
openMRI's block semantics onTCPSocket,TCPServerandSocket.#931's "shape of the fix" named the rest of the family in the same breath —
UNIXSocket,UDPSocket,UNIXServer— and nothing carried it out. Thosethree went on aliasing
openstraight tonew, so a block handed to them wasdiscarded without a word: no error, no warning, a body that simply never ran.
Three of six doors wired is this week's recurring shape, and the reason it
recurs is structural: the wrapper is shared, the wiring is per class.
UDPSocketnative: newFnsocketOpenWithBlock(udp, newFn)UNIXSocketnative: newSocksocketOpenWithBlock(sock, newSock)UNIXServernative: newSrvsocketOpenWithBlock(srv, newSrv)⛔ Checked before writing: the wrapper could have been a no-op here
socketOpenWithBlockcloses throughcls.methods["close"]— the class's ownmethod table, not its ancestors. A class whose
closeis inherited would havetaken the wrapper and closed nothing, and the fix would have read as done.
All three define
closedirectly:UNIXSocketthroughinstallStreamIO(
socket.go:480),UNIXServeratsocket_unix.go:144,UDPSocketatsocket_udp.go:170. That is also why the test assertsclosed?rather thantrusting the wrapper.
Each door proved by MUTATION, and each by ASSERTION
A test that passes before and after proves nothing, so each wiring was reverted
in turn:
UDPSocket[:udp, #<UDPSocket>, :block_never_ran]and[:udp_raise, false, :block_never_ran]UNIXSocket[:unixsocket, #<UNIXSocket>, :block_never_ran]UNIXServer[:unixserver, #<UNIXServer>, :block_never_ran, true]Three separate reds, each naming its own door and leaving the other two lines
intact — so this is one case per door, not one case that happens to cover one
of them. (That distinction is the whole lesson of the "one of N" defects this
repository has collected.)
⛔ The first draft failed with
NoMethodError: undefined method 'closed?' for nilinstead. That is a panic standing in for an assertion: it detects theregression but does not say what happened. Each case now prints
:block_never_ranfor a variable the block never set, so a discarded block is areadable diff.
⛔ And the
UNIXSocketcase deliberately has its servercloseat once,without reading. A server waiting for EOF would — with the door unwired — leave
the client open and hang this test rather than fail it: the exact failure
mode this whole issue is about, reproduced inside its own regression test.
Two traps recorded in the code rather than worked around
t.TempDir()puts the test's NAME in the path, andsun_pathis 104 byteson darwin. This test's name alone pushed the socket over the cap, and
bind(2)answersinvalid argument— which reads as a bug in the code undertest. The neighbouring tests fit only because their names are shorter, which
is not a property anyone would think to preserve when renaming one. A short
os.MkdirTempdirectory, with the reason in a comment.test's Ruby comments say
.newrather than a quotednewfor that reason.A fourth site, outside the socket family, filed rather than fixed
Deriving the population from the source instead of trusting #931's list found
internal/vm/resolv.go:199:Resolv::DNS.openwith a block is the same defect. MRI 4.0.7(
lib/ruby/4.0.0/resolv.rb:301-309, read on this machine) yields, returns theblock's value, and closes in an
ensure.It is not fixed here, and the reason matters: rbgo's
Resolv::DNS#closeraises
NotImplementedError(resolv.go:207, sitting in the "needs real DNSsockets" list — where closing a resolver that never opened one does not
belong). Wiring the block form naively would trade a silent discard for a raise.
Two steps, its own change, filed separately.
Checks
gotestper door: three mutations, three reds, verdicts above.internal/vmsuite green — 386 s, under a 1-minute load average of 61.gofmt -l .silent.TestEveryBlockingSocketCallReleasesTheGVLgreen at 33 calls over 542 files:this adds no blocking call, it only wraps existing constructors.
README.mdanddocs/nameUNIXServer/UDPSocketnowhere (the same grep findsREADME.md:230, so it can read), and the onlyTCPSocket.openmentions —repository README and the docs site's conformance page — describe the
historical cause of the net-http hangs, which this does not change.
Refs #931, #932, #916
(#931 and #916 stay open: #931's
gets(sep)-at-EOF half is untouched, and #916still has eight hanging files. #932 is the merged pull request this completes.)
🤖 Generated with Claude Code