Skip to content

fix: report a wasm plugin running out of stack as an error for the file, and give wasm 8 MiB of stack - #1463

Merged
dsherret merged 1 commit into
mainfrom
fix/wasm-stack-overflow
Nov 16, 2026
Merged

dsherret merged 1 commit into
mainfrom
fix/wasm-stack-overflow

Conversation

@dsherret

Copy link
Copy Markdown
Member

A wasm plugin that ran out of stack on a deeply nested file trapped, was reinitialized, ran out of stack again on the same file, and then stopped the whole run with "Critical error ... Cannot continue". None of the other files were formatted.

Running out of stack (wasmtime's Trap::StackOverflow) is now an error for that file only:

Error formatting a_deep.ts. Message: dprint-plugin-prettier ran out of stack, which happens when the code is nested too deeply.

dprint drops the instance that trapped without formatting the file again, and the other files still format. This also fixes the check after reinitializing, which looked at original_err where it meant reinitialize_err.

The wasm stack goes from 1 MiB to 8 MiB, and wasmtime's async stack size is set to match because wasmtime requires it to be larger. Plugins compiled from managed languages have large frames: Prettier compiled to Wasm ran out at a few hundred levels of nesting, about half of what Prettier gets in V8. With 8 MiB it goes 8 times as deep, which is further than V8 for every kind of nesting measured:

code 1 MiB 8 MiB Prettier in V8
a + a + ... (TS) 1,850 14,800 3,200
else if chain 475 3,800 1,237
f(f(...)) 287 2,300 900
nested objects (TS/JSON) 218 1,750 393
nested SCSS rules 256 2,075 975
nested Markdown lists 215 1,725 493
nested YAML block maps 116 950 375
nested HTML <div> 296 2,375 568

The thread stacks are reserved address space that the OS commits as it's touched, so this costs no memory until a file goes that deep. Every release target is 64-bit.

The test plugin is rebuilt with a should_overflow_stack case. The binary that was checked in was older than its source, which says the plugin formats a range (supports_range_formatting: true). With the rebuilt binary, the notebook test gives the plugin the range as it is. Expanding a range to whole lines is still covered by should_only_expand_the_range_for_plugins_that_do_not_format_one.

…le, and give wasm 8 MiB of stack

A plugin that ran out of stack on a deeply nested file trapped, was
reinitialized, ran out of stack again on the same file, and stopped the
whole run with a critical error. Running out of stack is now an error for
that file: the instance is dropped without formatting the file again, and
the other files still format.

Plugins compiled from managed languages have large frames, so 1 MiB of wasm
stack ran out at a few hundred levels of nesting where the same code in V8
goes about twice as deep. 8 MiB goes deeper than that. The stack is reserved
address space that is committed as it's touched.

The test plugin is rebuilt with a case that runs out of stack. The binary
that was checked in was older than its source, which says it formats a
range, so the notebook test now expects the range to be given as it is.
@dsherret
dsherret merged commit 910ed16 into main Nov 16, 2026
5 checks passed
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.

1 participant