Skip to content

fix(node): resume injected TLS and HTTP connections - #7

Merged
steipete merged 1 commit into
openclaw:mainfrom
RomneyDa:resume-injected-http-tls-connections
Sep 30, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
RomneyDa:resume-injected-http-tls-connections

Conversation

@RomneyDa

Copy link
Copy Markdown
Member

Summary

  • start the TLS read side when a paused socket is injected into tls.Server
  • resume paused sockets consumed by the JavaScript HTTP/1 fallback parser
  • cover both handoffs with Node-compatible regression tests

Why

OpenClaw's protected egress proxy intentionally pauses sockets while transferring ownership between an HTTP CONNECT server, a TLS server, and an HTTP server. Node consumes both injected sockets successfully. Bun accepted the handoffs but left the transports paused:

  • CONNECT returned 200, then the TLS ClientHello timed out
  • resuming the raw socket allowed TLS to complete, then the decrypted HTTP request timed out
  • resuming both handoffs completed the request

The installed OpenClaw fork build was reproduced at 699ba4ddd138994fb258de53669d481cdcf1016d (Bun 1.4.3). The same credential-free probe under Node 26.8.2 completed both handoffs.

Validation

  • Node 26.9.0: paused raw socket injected into http.Server returns HTTP 200
  • Node 26.9.0: paused raw socket injected into https.Server completes TLS and returns HTTP 200
  • [email protected] on all changed files
  • git diff --check

Full Bun execution requires the fork build/CI toolchain; the regressions are included in test/js/node/http/node-http.test.ts.

@steipete
steipete merged commit e89f965 into openclaw:main Sep 30, 2026
5 of 6 checks passed
steipete added a commit that referenced this pull request Sep 30, 2026
Merge upstream Bun through `ba3f27d1d1ce359d4eed842c135f0f6fba1acb00` into fork main, retaining upstream and contributor history. Land with a merge commit to retain upstream ancestry. All fork fixes #15, #7, #14, and #27 are incorporated and qualified.

The five conflict resolutions preserve the fork’s behavior while integrating upstream changes:

- Keep macOS `ProcessRetry` alongside upstream’s `Tty` event-loop flag.
- Keep the richer worker `execArgv` record and parser for preloads, TLS trust, CPU profiling, and addon/FFI restrictions; incorporate upstream’s invalid process-only flag reporting and its C++ error channel.
- Keep literal `?` file-URL handling in the module loader alongside upstream’s string-code-generation guards.
- Retain one upstream-positioned `ERR_WORKER_INVALID_EXEC_ARGV` mapping; both histories added it, and the automatic merge initially duplicated it.

The fork fixes landed since the previous sync `ee83b78b18` remain present: file-URL preloads (#22), response-finish diagnostics (#23), and macOS silent-run signal/stdio handling (#24). Earlier fork changes are retained by the merge. Upstream’s addon/FFI worker restrictions overlap the fork’s broader implementation; the shared behavior is retained in one parser, with upstream’s new invalid-flag handling added.

WebKit remains `f20ce7744553c910bcf16a33faf976af208de091` on both sides. Direct source inspection confirms that `DFGSSALoweringPhase.cpp` lowers `StringAt`, `StringCharCodeAt`, and `StringCodePointAt` to independent `CheckInBounds` nodes, and the pin includes `JSTests/stress/string-index-dce-bounds-check.js`. This is the upstream replacement for closed oven-sh/WebKit#578, so no pin rollback is needed. The release documentation now reflects that fix.

Final integration also retained both sides of the changelog conflict and added contributor credit for @SebTardif and @RomneyDa. The runtime plugin cache format remains version 34; the frozen upstream uses 33.

Native qualification exposed a pre-existing fork mismatch with two new upstream idle-sweep tests: cached idle state stays false until message timing clears, even after a bodyless response ends inside its handler. Explicit Node HTTP idle sweeps now derive response availability while preserving incomplete TLS handshakes, application-owned parser-error sockets, request bodies, partial heads, queued responses, and tunnels. Both upstream one-read/split-head tests pass unchanged, as does the existing parser-error ownership test. A TLS 1.2 relay control proves a sweep cannot close a handshake in progress. Node 26.10.0 confirms the bodyless close behavior.

Qualified head: `41dffc47212456d5ac80fc6fdddda08c4e4bfccc`, macOS arm64 release build (Bun 1.4.3, WebKit `f20ce7744553c910bcf16a33faf976af208de091`). No local SDK signpost patch was needed. Binary, hardening, duplicate-symbol, formatting, and applicable hosted checks passed. Codex review has no remaining accepted/actionable P0–P2 findings; the rejected non-regular-copy concern is ruled out by unchanged regular-file guards and eight matching baseline/candidate FIFO/device controls.

| File | Pass | Skip | Todo | Fail |
| --- | ---: | ---: | ---: | ---: |
| `test/js/bun/terminal/terminal.test.ts` | 97 | 2 | 0 | 0 |
| `test/js/bun/terminal/terminal-spawn.test.ts` | 23 | 2 | 0 | 0 |
| `test/js/bun/spawn/spawn.test.ts` | 165 | 24 | 0 | 0 |
| `test/js/node/child_process/child-process-stdio.test.js` | 9 | 0 | 0 | 0 |
| `test/js/node/http/node-http.test.ts` | 277 | 1 | 0 | 0 |
| `test/js/node/diagnostics_channel/diagnostics_channel.test.ts` | 26 | 0 | 3 | 0 |
| `test/js/node/sqlite/node-sqlite.test.ts` | 143 | 4 | 0 | 0 |
| `test/js/node/worker_threads/worker_threads.test.ts` | 172 | 0 | 0 | 0 |
| `test/cli/run/preload-test.test.js` | 2 | 0 | 3 | 0 |
| `test/cli/run/no-orphans.test.ts` | 15 | 9 | 0 | 0 |
| `test/cli/install/bun-install-lifecycle-scripts.test.ts` | 70 | 0 | 0 | 0 |
| `test/js/node/fs/fs.test.ts` | 660 | 16 | 0 | 0 |
| `test/js/node/fs/cp.test.ts` | 54 | 6 | 0 | 0 |
| `test/cli/run/transpiler-cache.test.ts` | 27 | 0 | 0 | 0 |
| `test/cli/test/isolation.test.ts` | 41 | 0 | 0 | 0 |
| `test/js/bun/plugin/plugins.test.ts` | 47 | 0 | 0 | 0 |
| `test/js/bun/plugin/plugin-namespace-drive-letter.test.ts` | 1 | 0 | 0 | 0 |
| `test/js/node/disallow-code-generation-from-strings.test.ts` | 28 | 0 | 0 | 0 |
| `test/js/node/http/node-http-server-abort-events.test.ts` | 105 | 0 | 0 | 0 |
| `test/js/node/http/node-http-server-close-drain.test.ts` | 31 | 0 | 0 | 0 |
| `test/js/node/http/node-http-connect.test.ts` | 80 | 1 | 2 | 0 |
| `test/js/node/http/node-http-upgrade-body.test.ts` | 11 | 2 | 0 | 0 |
| `test/js/node/http/node-http-req-socket-pause.test.ts` | 40 | 0 | 0 | 0 |
| `test/js/node/tls/node-tls-server.test.ts` | 99 | 0 | 0 | 0 |
| `test/js/node/tls/node-tls-wrapped-socket-close.test.ts` | 15 | 0 | 0 | 0 |
| `test/cli/install/bun-install-patch.test.ts` | 32 | 0 | 0 | 0 |
| `test/js/bun/io/bun-write.test.js (stream fallback only)` | 1 | 0 | 0 | 0 |
| `test/bundler/compile-argv.test.ts (compiled code-generation flags)` | 3 | 0 | 0 | 0 |
| **Total** | **2274** | **67** | **8** | **0** |

Filesystem and isolation suites used outer concurrency 2; nested stress work, assertions, and timeouts were unchanged. Lifecycle, TLS, and compiled-argument tests enabled the existing internal-test API at process startup (`BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING=1`, `BUN_GARBAGE_COLLECTOR_LEVEL=0`). Initial lifecycle/TLS invocations without those startup flags could not load `bun:internal-for-testing`.

Earlier runs encountered recursive-readdir and copy-stress timeouts; the same readdir workload exceeded its deadline on the pre-sync baseline. Both full filesystem suites passed on the final head. The terminal ESRCH test missed its real kernel race window once (its path-reached assertion failed); the unchanged complete file passed on retry. The known broader Bun.write Response timeout was reproduced on a separately built pre-change baseline during #27 qualification and is not claimed as a passing full-suite run here; the added stream-fallback regression passes.

Additional proof: normal/strict data/blob imports and Workers behaved as expected in all 16 probes; the compiled-argument tests preserve quoted strict-mode floors. OpenClaw smoke with the built runtime passed: `OpenClaw 2026.9.6 (23ad3a5)`. No tag or release is part of this PR.
@steipete

Copy link
Copy Markdown

Thanks again for this fix, @RomneyDa. It has been running in the OpenClaw Bun fork since it merged. Upstream oven-sh/bun has since landed oven-sh#44618, which covers part of the TLS-adoption side. The HTTP-fallback resume of a paused injected socket is still missing upstream, and there's no open upstream PR for it. Could you open that part against oven-sh/bun as well, with its regression test, and link it here? If you'd rather we file it with credit to you, just say so.

steipete pushed a commit to fuller-stack-dev/bun that referenced this pull request Oct 20, 2026
…module-graph.test.ts (oven-sh#45674)

### What does this PR do?

Fixes the flaky "50 graphs alive at once, each with its own state, then
all exit and are collected" in
`test/js/bun/module-graph/module-graph.test.ts`. It failed in 2 of 31
builds of main, 125686 to 127114 (Ubuntu 25.04 x64, Windows 11 aarch64)
and passed on the retry.

The test registered one array, `graphs[25].big`, with a
`FinalizationRegistry` and failed if 100 collections did not finalize
it. It now tracks the array of every one of the 50 graphs with
`Lifetimes` from `module-graph-lifetimes.ts`, as
`module-graph-gc.test.ts` does. There, an object that is not finalized
counts as kept alive only if a root reaches it in the debugging heap
snapshot, and the failure message is the path from that root.

Two things change with the helper, and the first is what makes the runs
below pass:

1. **Where the collection runs.** The helper calls `Bun.gc(true)` from a
timer callback, main's `collected()` from the continuation of the async
test. The `runInternalMicrotask` frame that holds the stale word
(artifact 2) is not on the stack in a timer callback. In 240 of 240 runs
all 50 arrays were finalized by the first collection.
2. **What is asserted if one is left.** Not that it was finalized, but
that no root reaches it.

### Why it failed

On main one of the 50 graphs outlives the collections in almost every
run, and the test fails when that one is number 25. Whole file, CI's
environment, 840 runs:

| graphs left after the collections | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| runs | 2 | 802 | 3 | 33 |

12 of the 840 failed. In the failing runs looked at (9 heap snapshots,
12 stack dumps) nothing in the heap holds the one that is left, and one
word on the native stack points at it.

All of what follows is the Linux x64 binary that CI built for main at
7f3bc6a, with `BUN_GARBAGE_COLLECTOR_LEVEL=1
BUN_RUNTIME_TRANSPILER_CACHE_PATH=0` as in `scripts/runner.node.ts`. The
failure needs both that environment and the whole file: 0 of 240 without
the environment, 0 of 1600 with the test alone. I did not look at the
Windows failure.

<details><summary>Artifact 1: the heap snapshot</summary>

`generateHeapSnapshotForDebugging()` right after the 100 collections.
These are the array and every cell from which it can be reached:

```
snapshot: 27033 cells, 99750 edges, 586 roots; arrays named `big` still in it: 1
  cell   1532 Promise                0x34cf520fa40  incoming edges 0  in `roots` no  a root reaches it no
  cell   1555 ModuleRecord           0x34cf527e980  incoming edges 3  in `roots` no  a root reaches it no
  cell   1573 ModuleNamespaceObject  0x34cef51dd50  incoming edges 3  in `roots` no  a root reaches it no
  cell   1591 JSModuleEnvironment    0x34cf5278950  incoming edges 3  in `roots` no  a root reaches it no
  cell   1626 Array                  0x34cef3755a0  incoming edges 2  in `roots` no  a root reaches it no
  cell   1631 Function               0x34cef45a100  incoming edges 2  in `roots` no  a root reaches it no
  cell   1653 Function               0x34cef45a0e0  incoming edges 2  in `roots` no  a root reaches it no
```

The snapshots of 8 other failing runs have the same seven kinds of cell,
with the `Promise` (fulfilled with the `ModuleRecord`) as the only one
without an incoming edge.
</details>

<details><summary>Artifact 2: the stack word and the frame that owns it
(gdb, same run as artifact 1)</summary>

The test writes the snapshot and sends itself SIGUSR2, and gdb stops
there.

```
Thread 1 "bun-profile" received signal SIGUSR2, User defined signal 2.
(gdb) info registers rsp rbp
rsp            0x7fffffffa0c8
rbp            0x7fffffffa240

words in [rsp, end of stack) = [0x7fffffffa0c8, 0x7ffffffff000) that point into one of those cells: 1
  0x7fffffffa8a0 holds 0x34cf520fa40 = Promise+0; it lies in the frame with rbp 0x7fffffffa8f0, at rbp-0x50
(gdb) x/gx 0x7fffffffa8a0
0x7fffffffa8a0:	0x0000034cf520fa40
(gdb) info symbol 0x1bccee0        # where that frame's callee returns to
JSC::runInternalMicrotask(...) + 6976

rbp chain
  openclaw#3  rbp 0x7fffffffa540  Bun::Process_functionKill
  openclaw#4  rbp 0x7fffffffa550  (JIT code)
  openclaw#5  rbp 0x7fffffffa5d0  op_call_ignore_result_return_location
  openclaw#6  rbp 0x7fffffffa680  llint_call_javascript
  openclaw#7  rbp 0x7fffffffa7e0  JSC::asyncFunctionGeneratorBodyCall
  openclaw#8  rbp 0x7fffffffa8f0  JSC::runInternalMicrotask            <- owns 0x7fffffffa8a0
  openclaw#9  rbp 0x7fffffffab70  JSC::MicrotaskQueue::drainWithUseCallOnEachMicrotask
  openclaw#10 rbp 0x7fffffffac00  JSC::VM::drainMicrotasks
  openclaw#11 rbp 0x7fffffffac20  Zig::GlobalObject::drainMicrotasks
  openclaw#12 rbp 0x7fffffffac50  <bun_jsc::event_loop::EventLoop>::exit
  openclaw#13 rbp 0x7fffffffacf0  TimerObjectInternals::fire
```

12 failing runs that dumped their own stack from `/proc/self/mem` show
the same: one word, `Promise+0`, at `rbp-0x50` of
`runInternalMicrotask`. In the 5 of them where I looked for it, the
frame's callee returns to the same `0x1bccee0`, which is
`JSMicrotask.cpp:2053`.

**Who wrote it.** A hardware watchpoint on `0x7fffffffa8a0`, set at the
first line of the test, sees 10 writes. The last one is the `Promise`:
`pushq %r14` in the prologue of `JSC::ModuleGraphLoadingState::create`
(`ModuleGraphLoadingState.cpp:71`, rbp `0x7fffffffa8b0`), which saves a
register of its caller.

**Why it stays.** The 100 collections run in the continuation of an
async function, so each runs under a `runInternalMicrotask` frame at
that same address. In the disassembly the function has 9 stores to
`-0x50(%rbp)`. Following the jump table and every branch, only case 14
of the switch (resume an async function) reaches the call at
`JSMicrotask.cpp:2053`, and none of the 9 stores is on a way to it. The
slot is inside a live frame, so stack sanitizing does not cover it.

So the graph that is left is the one whose load called `create` last at
that depth.
</details>

### How did you verify your code works?

**Failure rate.** Whole file, 12 copies side by side, main and this PR
in alternating rounds:

| | main | this PR |
|---|---|---|
| runs that failed | 12 of 1200 (all this test) | 0 of 1200 |

**What the snapshot says about a survivor.** With this PR there was none
to ask about: in those 240 runs, with a logging copy of the helper, the
snapshot was never taken. So this is main's test as it is, followed by
the helper's `Heap` asked about the 50 addresses, 1080 runs. The old
assertion failed in 12 of them. In 11 the array was in the snapshot with
no root reaching it, in 1 it was gone by then, in 0 a root reached it.

In 7 of the 1080 runs a root did reach two other arrays. In the one run
whose paths were printed, both start at `root(JITWorkList)`, a
compilation that is still running. `stillAlive` goes on collecting while
a root reaches something.

**Real references must fail.** One line added before `graphs.length =
0`. All 9 fail, with these messages:

| graph 25 is held by | message |
|---|---|
| a global, the namespace | `root(ProtectedValues) GlobalObject
-Property:held-> ModuleNamespaceObject -> ModuleRecord ->
JSModuleEnvironment -> Array` |
| a global closure over `inc` | `root(ProtectedValues) GlobalObject
-Property:held-> Function -> JSLexicalEnvironment -Variable:inc->
Function(inc) -> JSModuleEnvironment -> Array` |
| a local of the suspended test | `root(Output) FunctionCodeBlock -> ...
-Variable:pendingHeap-> Promise -> AsyncFunctionGenerator -> ...` |
| `setInterval(inc)` | `root(StrongHandles) StrongRootBlock -> Timeout
-Property:callback-> Function(inc) -> JSModuleEnvironment
-Variable:big-> Array` |
| `process.on(..., inc)` | `root(ProtectedValues) GlobalObject ->
Process -> Function(inc) -> JSModuleEnvironment -Variable:big-> Array` |
| a reaction of a pending promise | `root(ProtectedValues) GlobalObject
-Property:held-> Promise -> Function(inc) -> JSModuleEnvironment
-Variable:big-> Array` |
| a `FinalizationRegistry` held value | `root(ProtectedValues)
GlobalObject -Property:held-> FinalizationRegistry -> Array` |
| a `WeakMap` value of a live key | `root(Output) Array` |
| an `AbortSignal` listener | `root(WeakSets) AbortSignal ->
Function(inc) -> JSModuleEnvironment -Variable:big-> Array` |

With `globalThis.held = graphs[7]` instead, main's test passes 5 of 5
and this PR's fails 5 of 5.

**Debug build**, default timeout: the test passes 6 of 6 alone and in 6
of 6 runs of the whole file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants