Repository navigation
fix(javascript): match resource release methods to the acquired handle - #7773
Conversation
Every acquisition family admitted every release method, so `h.close()`,
`h.destroy()` and `h.end()` each resolved as a complete release of whatever the
binding held. Node exposes a different subset per acquisition, and the rejected
pairs throw at the call site instead.
Measured on Node 24.22.1:
| acquisition | value | release members |
| --- | --- | --- |
| `fs.openSync` | number | none |
| `fs.open` (callback) | undefined | none |
| `fs.createReadStream` | ReadStream | `close`, `destroy` (`end` is the byte-offset field) |
| `fs.createWriteStream` | WriteStream | `close`, `destroy`, `end` |
| `fs/promises.open` | FileHandle | `close` |
| `net.connect` | Socket | `destroy`, `end` |
| `tls.connect` | TLSSocket | `destroy`, `end` |
So `fs.openSync(...)` + `fd.close()`, `createReadStream(...)` + `.end()`,
`net.connect(...)` + `.close()` and the FileHandle cases emitted a `releases` /
`resolved` fact for a call that throws.
Carry the specifier with each acquisition candidate, list the release methods
each pair actually has, and emit no release when the pair is not one of them. A
release stays `complete` only when the binding held exactly one acquisition and
that acquisition admitted the method.
`tls.createConnection` is not a Node export at all: `'createConnection' in
require('node:tls')` is false and the ESM import does not link. Drop it from the
table so a `tls.createConnection` call yields no acquisition.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; no blocking issue remains. SummaryThe PR matches release methods to the acquired Node resource and removes the unsupported
Reviews (2) · Last reviewed commit: "fix(javascript): cover a mixed-family bi..." · Reviewed by Greptile |
…ease greptile asked for the mixed-family case: a binding that can hold either a FileHandle or a socket, then calls close(). The FileHandle is the only linked acquisition and the release stays partial. That case also showed the `candidates.length === 1` guard was dead: an acquisition of another family is not in `linked`, so `holdsOnlyAcquisitions` already returns false for it and the release already stayed partial without the guard. Removing the guard and keeping the test means the behaviour is now pinned by a test rather than by two overlapping conditions.
|
Addressed in Two mixed-family cases are now in the table, both expecting
Writing the first one also showed the So rather than keep two overlapping conditions, the guard is gone and the behaviour is pinned by the test instead. |
Summary
Every acquisition family admitted every release method, so
h.close(),h.destroy()andh.end()each resolved as a complete release of whatever the binding held. Node exposes a different subset per acquisition, and the other pairs throw at the call site.Measured on Node 24.22.1:
fs.openSyncfs.open(callback)fs.createReadStreamclose,destroy(endis the byte-offset field)fs.createWriteStreamclose,destroy,endfs/promises.openclosenet.connectdestroy,endtls.connectdestroy,endProblem and expected behavior
RELEASE_METHODSinsrc/domain/javascript/javascriptSemanticResources.tswas family-blind, so a member call on any single-acquisition binding becameresolution: "complete"and was projected asreleases/resolved. Six pairings refute that — Node throws at the call site, so the resource is never released while the lifecycle is reported as covered:fs.closeSync(fd)/fs.close(fd), the descriptor's real release, is not a member call and was not modelled at all, so the descriptor lifecycle was wrong in both directions.tls.createConnectionis not a Node export either:'createConnection' in require('node:tls')isfalseand the ESM import does not link (SyntaxError: does not provide an export named 'createConnection'). The acquisition was therefore fabricated for a module that does not load.net.createConnection === net.connect, so only thetlsentry was wrong.Change and scope
Carry the builtin specifier with each acquisition candidate, list the release methods each specifier/method pair actually exposes, and emit no release when the pair is not one of them. A release stays
completeonly when the binding held exactly one acquisition and that acquisition admitted the method. DropcreateConnectionfrom thetlsentry.Three files: the resource methods table, the resource collector, and a new test.
Contract and boundary impact
collectJavaScriptSemanticResources).releasesfacts become accurate for these pairings.tsc --noEmitandoxfmt --checkpass.Expected effects:
Evidence and regression coverage
javascriptSemanticAnalysis.release_families.test.tsadds 10 cases. The sevenrejectedrows fail on unmodifiedmainand pass here; the threeacceptedrows keepresolution: "complete", so the filter is pure narrowing.--project domainis 8858 passed.Validation performed
npx vitest run --project domain— 8858 passednpx vitest run src/application/javascript— 566 passed | 7 skippednpx vitest run tests/acceptance/applications/javascriptBuiltinDefaultsCli.test.ts— 6 passednpx tsc --noEmit -p .— exit 0npx oxfmt --checkon the three changed files — exit 0npm run knipreports only the pre-existingHexRecordRegionMetadatafinding from Deep static (knip) on main reports unused exported type HexRecordRegionMetadata since #7136 #7717, which fix: remove unused hex record metadata type #7718 already coversCompatibility, safety, and release
No breaking change. The change narrows an overstated claim; no public contract, CLI output shape, or IR type changes.
Author readiness
Human owner: @XiaoBinGan
Before merge
type(scope): outcome.