Skip to content

Abort "Lazy deopt after a fast API call with return value is unsupported" in Buffer.byteLength called from maybePrepareFinalChunk / res.end(string) #66870

Open

Description

@jakesalvesen

Version

v26.10.0 (node-26.10.0-linux-x64 from actions/setup-node@v5).

The same abort also occurred on 2026-08-28 in a second CI run on the then-current 26.x build, so it is not a one-off.

Platform

Linux 6.x x64 (GitHub Actions ubuntu-latest runner)

All local attempts to reproduce on Windows 11 x64 with v26.10.0 and v26.12.0 failed (details below).

Subsystem

http / buffer (V8 fast API call inside Buffer.byteLength, reached from _http_outgoing).

What steps will reproduce the bug?

There is no standalone minimal repro yet - this is the report of a real production abort with a complete V8 stack. The reproducing workload is a Vite dev server under sustained browser traffic:

  1. Run vite (8.3.4) on Linux with Node 26.10.0.
  2. Load a page that pulls a large pre-bundled dependency chunk. In this case node_modules/.vite/deps/lib-*.js is 17,416,067 bytes; Vite's send helper appends an inline source map, producing a String[43640789].
  3. Drive continuous Playwright traffic for roughly ten minutes (261 browser tests hitting the dev server).
  4. The dev-server process aborts and every later connection fails with net::ERR_CONNECTION_REFUSED.

The abort itself:

abort: Lazy deopt after a fast API call with return value is unsupported

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x7f49dce3ea76]
    1: byteLength [0x3fc66a4d8b91] [node:buffer:923] [bytecode=0xe4e3e6b3dc1 offset=88](this=0x3fc66a4d72e1 <JSFunction Buffer (sfi = 0x385470d41a39)>#0#,0x3ba819d309a1 <String[43640789]: uc"...<truncated>>">#1#,0x36331f5c0011 <undefined>)
    2: maybePrepareFinalChunk(aka maybePrepareFinalChunk) [0x67fc7c1ba61] [node:_http_outgoing:1069] [bytecode=0x1de7ebdcd5d1 offset=58](this=0x36331f5c0011 <undefined>,0x3ba819d357d9 <ServerResponse map = 0x25850d03f771>#2#,0x3ba819d309a1 <String[43640789]: uc"...<truncated>>">#1#,0x36331f5c0011 <undefined>)
    3: end [0x67fc7c1e8b9] [node:_http_outgoing:1197] [bytecode=0x1de7ebdcd0b1 offset=117](this=0x3ba819d357d9 <ServerResponse map = 0x25850d03f771>#2#,0x3ba819d309a1 <String[43640789]: uc"...<truncated>>">#1#,0x36331f5c0011 <undefined>,0x36331f5c0011 <undefined>)
    4: send$1(aka send$1) [0x1b9f12a631e9] [file:///home/runner/work/<repo>/node_modules/vite/dist/node/chunks/node.js:~17519] [pc=0x7f49bd3567a7](...)
    5: viteTransformMiddleware [file:///home/runner/work/<repo>/node_modules/vite/dist/node/chunks/node.js:~20159]

Frame 1 is Node's own Buffer.byteLength (node:buffer:923) and frame 2 is Node's maybePrepareFinalChunk (node:_http_outgoing:1069), whose source is captured in the report:

function maybePrepareFinalChunk(msg, chunk, encoding) {
  if (typeof chunk !== 'string' && !isUint8Array(chunk))
    return false;

  if (msg.destroyed || msg.strictContentLength)
    return false;

  if (!msg._header) {
    msg._contentLength = typeof chunk === 'string' ?
      Buffer.byteLength(chunk, encoding) : chunk.byteLength

So the aborting path is res.end(string) with msg._header unset, which calls Buffer.byteLength(hugeString, undefined).

How often does it reproduce? Is there a required condition?

Twice in two CI runs on Linux x64, roughly ten minutes into sustained dev-server traffic. It did not reproduce in short bursts.

I could not reproduce it locally on Windows 11 x64, with either v26.10.0 or v26.12.0, using:

  • 300 sequential res.end() responses of a 43.6 MB string;
  • 3,000 responses of a 1 MB string alternating with a Buffer and with res.end(string, 'utf8') to vary the call site;
  • 2,800 requests for the real 43.8 MB Vite dev-server chunk (the same send path as the crash) over keep-alive sockets;
  • the same runs with --deopt-every-n-times=3 to force deopts at deopt points.

So the trigger appears to need more than "a large string through res.end" - possibly the specific optimized-code state of the Vite middleware chain on the CI runner, or a longer warm-up than a few thousand requests.

What is the expected behavior? Why is that the expected behavior?

Serving a large string with res.end() should never abort the process. Payload size and repetition may cost memory and CPU, but a correct runtime either deoptimizes or keeps the optimized code; it does not terminate.

What do you see instead?

The process aborts with Lazy deopt after a fast API call with return value is unsupported, killing the server mid-suite.

Additional information

The fatal string is a V8 bailout reason, v8/src/codegen/bailout-reason.h:

"Lazy deopt after a fast API call with return value is unsupported"

and Buffer.byteLength is exactly a fast API call with a return value, per src/node_buffer.cc:

uint32_t FastByteLengthUtf8(...) {
TRACK_V8_FAST_API_CALL("Buffer::FastByteLengthUtf8");
static CFunction fast_byte_length_utf8(CFunction::Make(FastByteLengthUtf8));

The corresponding V8 work item is "Add deopt support after fast api calls with return values" (https://issues.chromium.org/issues/418936518), so this may be a V8 limitation that Node surfaces. Filing here because the aborting frame is Node's _http_outgoing code and the call is Node's own Buffer.byteLength, and because the practical fix may be on the Node side.

Our workaround, in case it is useful for triage, is to make the caller hand Node bytes so the fast API is not on the path (res.end(Buffer.from(content)) instead of res.end(content)); with that in place the dev server survives the same workload.

If a standalone reproduction is required before this is actionable, I am happy to run a loop on a Linux runner against a candidate commit - please say which shape you want (for example a node:test server plus a client loop, or a V8 d8 snippet) and I will provide it.

Activity

  1. jakesalvesen commented on Oct 20, 2026

    @jakesalvesen
    Author

    Adding the reproduction attempts so triage does not have to repeat them.

    Environment matched to the crashing run (Node 26.10.0, Windows 11 x64): I started the same Vite 8.3.4 dev server on the exact node-26.10.0 binary (verified via ExecutablePath) and requested the same 43.8 MB pre-bundled chunk the crashing stack shows (send$1 receives String[17354770], which matches the 17,416,067-byte source chunk, and maybePrepareFinalChunk receives String[43640789] after Vite appends the inline source map):

    • 3,000 keep-alive requests over 4 sockets, 125,335 MiB served in 161 s - no abort, server still answering afterwards.
    • 240 fresh-connection requests, 10,027 MiB - no abort.
    • 3,000 res.end() calls on a synthetic 1 MiB string alternating with Buffer and res.end(string, 'utf8') to keep the call site polymorphic - no abort.
    • 300 res.end() responses of a 43.6 MB string - no abort.
    • The same on v26.12.0 with the same results, plus --deopt-every-n-times=3 to force deopts at deopt points.

    So volume alone is not the trigger. Differences from the crashing run that I could not reproduce locally:

    1. The crashing process had been up for ~10 minutes serving 261 Playwright tests, i.e. hundreds of distinct module URLs and a browser sending real navigation/fetch traffic - not one URL in a loop. Call-site polymorphism in send$1 and the Vite middleware chain is therefore much broader than in my loop.
    2. Sustained allocation pressure from repeatedly materializing ~43 MB strings, with GC/compaction active, plus several browser workers in parallel.
    3. Linux x64 in CI versus Windows x64 locally.

    If helpful, the minimal shape I would try on a Linux runner is: one node:http server that responds with res.end(bigString) where msg._header is still unset (so maybePrepareFinalChunk runs), several concurrent clients requesting a rotating set of distinct URLs, and the server pinned to v26.10.0. I am happy to run that against a candidate build if you tell me which one - I just cannot execute Linux runners from here.

  2. jakesalvesen commented on Oct 20, 2026

    @jakesalvesen
    Author

    Linux results, so this does not get assumed to be a Windows-only artifact - it is not reproducible here either, even on Linux with the crashing Node build.

    Setup: WSL2 guest (Ubuntu 24.04.5, kernel 6.18.54.1-microsoft-standard-WSL2, 24 vCPU) running the official node-v26.10.0-linux-x64 build, i.e. the same version as the crashing CI run.

    Run 1 - synthetic server that reproduces the failing shape exactly (res.end(string) with msg._header unset so maybePrepareFinalChunk calls Buffer.byteLength), 8 concurrent keep-alive clients over 2,000 requests / 61 GB, rotating between the crashing payload sizes (43,640,789 and 17,354,770 chars), a Buffer variant, a HEAD variant and a small variant, with a timer allocating ~24 MB every 250 ms to keep GC/compaction active: no abort.

    Run 2 - same, but the large payload is a ConsString (code + sourceMappingURL prefix + base64), which is what Vite's send() actually hands to res.end() after appending the inline source map, rather than a flat 'x'.repeat(n): 2,400 requests / 73 GB: no abort.

    I also tried to run the real Vite 8.3.4 dev server inside the Linux guest. That failed for a mundane reason: this checkout's node_modules was installed on Windows, so rolldown has only the win32 native binding and the Linux server cannot start (Cannot find module '@rolldown/binding-linux-x64-gnu'). A npm ci inside the guest would be needed to run that variant, which I did not do.

    So the trigger needs more than the call shape, the payload sizes, the cons-string flattening, volume, concurrency and GC pressure. My best remaining hypothesis is that it depends on the state of the large Vite middleware chain after minutes of varied traffic (deep, polymorphic call sites feeding send()), or on a specific deopt point in that chain, rather than on Buffer.byteLength itself. If a collaborator can share the --trace-deopt output or a core dump from a recurrence, I can narrow it from there.

  3. jakesalvesen commented on Oct 20, 2026

    @jakesalvesen
    Author

    One more diagnostic that may save time: on Linux with the crashing Node build, I ran the synthetic server under --trace-deopt --deopt-every-n-times=2 while a client drove 300 mixed requests (43.6 MB cons string, 17.35 MB string, Buffer, HEAD, small). Result: 54 deopt events were logged, none in maybePrepareFinalChunk / _http_outgoing / Buffer.byteLength, and no abort.

    That suggests the abort needs maybePrepareFinalChunk itself to be running optimized TurboFan code when the lazy deopt is requested - in my loop it never tiered up (the frame is only reached once per response, and my sockets were dominated by socket-write work rather than that function). A loop would probably have to drive that exact function into optimized code thousands of times while something invalidates it, which is consistent with a long, varied CI session rather than a tight loop.

    If that matches your reading, the actionable ask on the reporter side is --trace-deopt (or --trace-opt --trace-deopt) enabled on the CI runner so the next recurrence records which deopt triggered the bailout, and I can wire that into our pipeline.

  4. lazerg commented on Oct 20, 2026

    @lazerg
    Contributor

    It's partly a V8 limitation and partly on Node's side. The abort itself is deliberate in V8: since 517cf1b a lazy deopt after a fast API call that returns a value just crashes, and that TODO (crbug.com/418936518) is still open on V8 main, so a V8 update won't fix it yet. What likely triggers the deopt is Node's FastByteLengthUtf8: both String::ValueView and Utf8LengthV2 flatten a concatenated string, which means allocating ~87 MB on the JS heap inside the fast call, something V8's fast API rules say fast callbacks shouldn't do. A GC there can invalidate the optimized caller, which would explain why it only shows up after long runs under memory pressure. Until the fast path avoids that, your Buffer.from(content) workaround is the right fix.

  5. jakesalvesen commented on Oct 20, 2026

    @jakesalvesen
    Author

    Thanks, that matches what the stack shows and gives me something testable.

    Confirming the flatten: with the server on a tight heap (--max-old-space-size=192) and a fresh code + sourceMappingURL prefix + base64 ConsString per response (43,640,789 chars, same lengths as the crash), GC runs inside Buffer.byteLength constantly - Scavenge 130.2 (131.7) -> 88.5 (90.1) MB, allocation failure every ~20 ms across 4,000 requests. So the ~43 MB flatten allocation and the mid-fast-call GC are both reproduced.

    Still no abort, and the crash stack suggests why: frames 1-3 (byteLength, maybePrepareFinalChunk, end) are all [bytecode=... offset=...], while only frames 4-5 (send$1, viteTransformMiddleware) carry [pc=0x...]. So the optimized frame that V8 invalidates is the Vite caller, not Node's own _http_outgoing frame, and the lazy deopt point that trips is in that optimized caller. Reproducing it therefore needs an optimized JS caller performing the res.end(hugeConsString) call under heap pressure, not just Node internals under pressure. I can try to shape a synthetic caller to match (a hot, optimized function that calls res.end(consString)), but I wanted to check with you first: does that reading match the intended constraint, or should the optimized caller be irrelevant because the deopt point is attributed to the callee's frame?

    Either way this settles the practical question for us: the Buffer.from(content) workaround stays until V8 lands crbug.com/418936518 or the fast path stops allocating for cons strings. If a Node-side mitigation is welcome in the meantime (for example skipping the fast path for large or non-flat strings in maybePrepareFinalChunk, or deferring _contentLength to the write path), I am willing to prepare the patch and the test.

  6. jakesalvesen commented on Oct 20, 2026

    @jakesalvesen
    Author

    One check that may save you time: this is not already fixed on main. The implementation moved out of lib/_http_outgoing.js into lib/internal/http/outgoing.js, and the same call is still there:

    // lib/internal/http/outgoing.js, current main
    function maybePrepareFinalChunk(msg, chunk, encoding) {
      ...
      if (!msg._header) {
        msg._contentLength = typeof chunk === 'string' ?
          Buffer.byteLength(chunk, encoding) : chunk.byteLength;

    So the flatten-inside-fast-call path survives the refactor, and the abort stays reachable until either V8 implements the deopt or Node stops computing a string length through the fast path there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions