Repository navigation
Description
What versions & operating system are you using?
System:
OS: Linux 7.0 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
CPU: (32) x64 AMD Ryzen 9 9950X 16-Core Processor
Memory: 16.45 GB / 30.45 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 22.14.0
npm: 10.9.2
pnpm: 11.24.0
npmPackages:
miniflare: 4.20260730.0 => 4.20260730.0
Please provide a link to a minimal reproduction
Describe the Bug
The local Hyperdrive proxy pipes the workerd client socket to the database socket. Only the database side gets an error listener.
In packages/miniflare/src/plugins/hyperdrive/hyperdrive-proxy.ts on main:
createPlainTCPConnectionattachesdbSocket.on("error", ...)setupTLSConnectionattachestlsSocket.on("error", ...)clientSocketgets nothing, at any of the four places it is piped:#handleConnection,handlePostgresTlsConnection,handleMySQLTlsConnection,setupTLSConnection. It also gets nothing before those pipes exist: on the TLS paths,#handleConnectionwrites to the database, reads the reply and runs a TLS handshake first, and a client that resets during that window crashes the process the same way
pipe() does not cover this. It attaches an onerror handler to the destination, but that handler removes itself and re-emits once no other listener is left. So when the client socket errors after the pipes are set up, nothing is listening, and the whole Node process exits. That takes down wrangler dev, getPlatformProxy(), or a vitest run.
Steps to reproduce
git clone https://github.com/Pduhard/miniflare-hyperdrive-crash-repro
cd miniflare-hyperdrive-crash-repro
npm install
npm run repro:half-close
npm run repro:resetrepro:half-close runs a TCP server that speaks just enough of the Postgres protocol to negotiate TLS, then streams data. A Worker connects through a Hyperdrive binding and half-closes its socket while that data is still arriving. Nothing reaches into Miniflare internals.
repro:reset covers the other window: it talks to the proxy port directly and resets the connection while the proxy is still negotiating TLS with the database, before any pipe exists.
Expected: the connection is torn down and Miniflare keeps running.
Observed: the process exits 1 on an uncaught error.
Which configurations reach this code
Since #13390 the proxy is skipped when sslmode=disable, so that mode no longer reaches it. require, prefer, verify-ca and verify-full still do, which is the ordinary setup for developing locally against a hosted Postgres that requires TLS.
| version | sslmode=disable |
sslmode=require |
|---|---|---|
4.20260424.0 |
exits 1 | exits 1 |
4.20260730.0 |
20 of 20 attempts survive | exits 1 |
The same code is on main today.
Please provide any relevant error logs
node:events:496
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:87:19)
Emitted 'error' event on Socket instance at:
at Socket.onerror (node:internal/streams/readable:1028:14)
at Socket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}
Socket.onerror at readable.js:1028 is the listener pipe() installed on the destination, re-emitting because nothing else was listening. Depending on whether the write lands just before or just after the peer's FIN, the same failure also shows up as Error: This socket has been ended by the other party at Socket.writeAfterFIN.
PR: #15769. It attaches the listener as soon as the connection is accepted and at each pipe site, with a regression test for each of the two windows in packages/miniflare/test/plugins/hyperdrive/proxy.spec.ts. Both tests fail on main.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
workers-devprod commentedon Sep 22, 2026
Automated triage
Issue assessment
package:miniflare(high)product:hyperdrive(high)Actionability and missing information
Miniflare's Hyperdrive proxy lacks an error listener on the client socket at its four pipe sites, so a client-side socket error becomes an unhandled error event that crashes the Node process; report includes minimal repro, versions, environment, and error logs.
Reproduction reason: The report provides concrete steps, version comparisons, and consistent error output for a crash that still occurs in current releases, so automatic reproduction can validate it.
Reproduction
Evidence and attempted steps
Steps attempted:
cd project && pnpm install # pins miniflare 4.20260730.0 exactlynode repro.mjsfor i in 1 2 3 4 5; do node repro.mjs > /tmp/final-$i.log 2>&1; echo "run $i: exit=$?"; donerm -rf node_modules && pnpm install --frozen-lockfile && pnpm reproduceExpected behavior: The client-side connection is torn down gracefully and the Node process running Miniflare (wrangler dev / getPlatformProxy() / a Miniflare Node-API process) keeps running; the socket error is handled rather than crashing the process.
Observed behavior: In 5/5 consecutive runs (plus one clean-state run after a frozen reinstall), the Node process running Miniflare exited 1 during the Worker request with the exact reported signature: an uncaught 'error' event on the Hyperdrive proxy's client socket — "Error: write EPIPE" (errno: -32, syscall: 'write'), "Emitted 'error' event on Socket instance at: at Socket.onerror (node:internal/streams/readable:1028:14)" — the same re-emit site (readable.js:1028, the listener installed by pipe()) and same error as the issue's log.
Artifact: Download reproduction archive (Cloudflare Access required).
This summary was generated by an LLM and may contain errors. Please verify its findings.
Triage bot commands and options
Repository collaborators with write or admin access can trigger actions by commenting on this issue:
@workers-devprod reproduce: Attempt to reproduce the issue using its description and recent comments.rikbrown commentedon Sep 24, 2026
A reload in
wrangler devis another trigger for this crash, and in local development it is the common one.Each reload (
Miniflare#setOptions()) stops the workerd process and starts a new one. The connections that a Worker holds open through a Hyperdrive binding close with the old process. If a connection still has unread data, for example a query result that arrived during the reload, the OS resets it. The proxy's client socket then emitsread ECONNRESETwith no listener, andwrangler devexits 1 directly after the reload message:The error prints once for each open connection. With a connection pool and a TLS database, a file edit while the Worker serves requests is enough to cause it.
The script below uses only the public API. A fake Postgres server accepts the SSLRequest, upgrades to TLS and sends data. A Worker opens two
env.DB.connect()sockets and holds them, then the script callssetOptions(). Results on macOS 27.0, Node 24.12.0, workerd 1.20260921.1:MODE=burst(data left unread)MODE=stream(data still arriving)5.20260921.1-alpharead ECONNRESETwrite EPIPE5.20260921.0-alpha+ the change in #15769The same script also shows a separate leak: each reload leaves the previous proxy servers listening, also after
dispose(). That is #15843.repro.mjs
phoorichet commentedon Oct 9, 2026
Still reproduces on the latest alpha, and through
@cloudflare/vite-plugin:5.20260918.0-alpha(what@cloudflare/[email protected]installs) and5.20261006.1-alpha(currentlatest):setupTLSConnectionand the other pipe sites are unchangedreact-router devwith@cloudflare/vite-plugin, a Hyperdrive binding with a local connection string to a hosted Postgres oversslmode=verify-fullHow we hit it without trying: the hosted Postgres ran out of connection slots (
53300 remaining connection slots are reserved...), sockets got reset, and the dev server died with:Both windows from the issue reproduce through the vite plugin, by connecting to the proxy's loopback port and calling
resetAndDestroy():So the entry listener in #15769 is needed in practice, not just in theory. We're carrying a
bun patchwith both until #15769 ships.Pduhard commentedon Oct 22, 2026
Fixed on main by the proxy rework (#15879, #14900): a client socket error mid-stream or a reset during negotiation no longer takes down the process. Checked by running the two tests from #15769 against main.