Skip to content

bug: WASM engine segfaults after repeated builds in same process #409

@carlos-alm

Description

@carlos-alm

Found during dogfooding v3.1.2

Severity: Low
Command: node scripts/benchmark.js

Reproduction

node scripts/benchmark.js
# Run sequence: WASM full build → 3x no-op → 1-file rebuild #1 → #2 → SEGFAULT on #3

Expected behavior

WASM engine should survive repeated incremental builds in the same process without crashing.

Actual behavior

After 6+ WASM builds in the same Node.js process (1 full + 3 no-op + 2 one-file), the 3rd one-file rebuild segfaults (exit code 139). The incremental benchmark script (incremental-benchmark.js) runs the same pattern but survives — suggesting memory pressure or accumulated state in tree-sitter WASM is the trigger.

Root cause

Likely tree-sitter WASM memory accumulation across repeated parser invocations in the same process. The build benchmark runs more operations before reaching the 1-file phase (full build + queries + no-op) compared to the incremental benchmark, which may push WASM memory past the threshold.

Environment

  • Platform: Windows 11 Pro, win32-x64, Node v22.18.0
  • tree-sitter-wasms: as of v3.1.2

Suggested fix

  • Investigate if tree-sitter WASM parsers are properly disposed between builds
  • Consider calling parser.delete() on WASM parsers after each build cycle
  • Or run WASM benchmarks in a child process to isolate memory

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdogfoodFound during dogfooding

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions