Skip to content

Commit fe9c206

Browse files
committed
fix(transport): refs PerryTS/perry#536 — call net.createConnection(port, host) on Perry, not (host, port)
The perry path of `openSocket` swapped Node's positional argument order based on a mistaken assertion in the file header. Perry's `net.createConnection` has always matched Node's documented `(port[, host][, connectListener])` — see `crates/perry-codegen/src/lower_call.rs` (NA_F64 first, NA_STR second) in the perry tree. Under the wrong order Perry coerced the host string to a port (NaN-coerced) and the port number to a host pointer, returning an invalid socket handle that silently no-op'd through every `sock.on(...)` registration. `await connect(...)` then never resolved against any MySQL server, surfacing as an immediate exit with no rows on the bare `await pool.query("SELECT 1 AS n")` shape from the issue's repro. Header comment rewritten to reflect Perry's actual `(port, host)` contract. The Node.js code path is unchanged — Node accepts the object form `({ host, port })` which the driver already used. Bumps to 0.1.3 and adds a CHANGELOG entry. After running with perry >= v0.5.652 (which includes #536's runtime-side fixes for [].pop()/shift() returning undefined and ext-net active-handles wiring), the issue's repro now returns the SELECT 1 row end-to-end.
1 parent 3d2f729 commit fe9c206

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## v0.1.3
4+
5+
- Fix the Perry path of `transport/net-socket.ts::openSocket` to call
6+
`net.createConnection(port, host)` matching Node's documented
7+
positional signature. The pre-fix call passed `(host, port)` based
8+
on a mistaken assertion in the file's own header comment that Perry
9+
used a different order — Perry has always matched Node's
10+
`(port, host)` (see `crates/perry-codegen/src/lower_call.rs` in the
11+
perry tree). Under the wrong order Perry coerced the host string to
12+
a port (NaN) and the port number to a host pointer, returning an
13+
invalid socket handle that silently no-op'd through every subsequent
14+
`sock.on(...)` registration — `await connect(...)` then never
15+
resolved against any MySQL server. Header comment rewritten to
16+
reflect Perry's actual `(port, host)` contract. PerryTS/perry#536.
17+
- The Node.js code path is unchanged — Node accepts the object form
18+
`({ host, port })` which the driver already used.
19+
320
## v0.1.2
421

522
- Fix binary decoders for `DATE`, `DATETIME`/`TIMESTAMP`, and `TIME`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@perryts/mysql",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Pure-TypeScript MySQL/MariaDB wire-protocol driver. Runs on Node.js and Bun, and compiles to a native binary via Perry (LLVM). Zero native dependencies.",
55
"keywords": [
66
"mysql",

src/transport/net-socket.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Cross-environment socket adapter. Perry and Node/Bun both ship a
2-
// Node-compatible `net` module, but `createConnection` has slightly
3-
// different signatures:
4-
//
5-
// - Perry (perry-stdlib): net.createConnection(host, port)
6-
// - Node (node:net): net.createConnection({ host, port })
2+
// Node-compatible `net` module. Both accept the positional
3+
// `(port, host)` form (matching Node's documented signature
4+
// `net.createConnection(port[, host][, connectListener])`); Node
5+
// additionally accepts the object form `({ host, port })`.
76
//
87
// This file is the only place in the driver that cares. Everything else
98
// consumes the returned `Socket` interface.
@@ -52,5 +51,11 @@ export function openSocket(host: string, port: number): Socket {
5251
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5352
return (net as any).createConnection({ host: host, port: port }) as Socket;
5453
}
55-
return net.createConnection(host as never, port as never) as unknown as Socket;
54+
// Perry positional signature is `(port, host)` per Node's documented
55+
// `net.createConnection(port[, host])`. Pre-fix this called
56+
// `(host, port)` — perry coerced the host string to a port (NaN)
57+
// and the port number to a host pointer, returning an invalid
58+
// socket handle that silently no-op'd the rest of the connection
59+
// lifecycle. PerryTS/perry#536.
60+
return net.createConnection(port as never, host as never) as unknown as Socket;
5661
}

0 commit comments

Comments
 (0)