Skip to content

fix: update NAPI to fix V8 foreground task crashes and GC stalls - #170

Merged
syrusakbary merged 1 commit into
mainfrom
fix/update-napi-foreground-tasks
Oct 25, 2026
Merged

syrusakbary merged 1 commit into
mainfrom
fix/update-napi-foreground-tasks

Conversation

@syrusakbary

Copy link
Copy Markdown
Member

Summary

Advance the napi submodule from a65e9cb8 to NAPI main at dfc50c75. It brings two V8 provider fixes that Edge depends on:

  • Fix use-after-free when handing V8 foreground tasks to the enqueue hook napi#113 stops the provider from touching a foreground task after handing it to Edge's enqueue hook (EnqueueForegroundTaskFromEngine). When the hook refused a task, for example once env cleanup had started, the provider freed it a second time. Native Edge crashed in PostTaskCommon (SIGSEGV/SIGBUS), mostly in node:vm and node:worker_threads tests at process exit.
  • Run one V8 fallback foreground task per event-loop checkpoint napi#117 runs at most one fallback foreground task per event-loop checkpoint and reports that it ran one. Self-reposting GC tasks no longer keep one checkpoint busy, which stalled the V8 WASIX event loop and streamed responses. Edge's loop already treats the host_tasks_admitted bit as "take another turn without waiting on libuv", so no Edge change is needed.

The bump also brings wasmerio/napi#87, #88, #90, #91, #92, #103 and #104. Public header changes are comments only.

Testing

macOS arm64, Release, Edge main (18b0ce9e) with this pin:

Check Result
make test-only (V8 native) 1749/1749
make test-intl, make test-lang (V8 native) pass
make validate-wasix-imports, make test-wasix-import-validator pass
make test-wasix-v8-only (-j 8) 1676/1676
make test-wasix-v8-process pass
make framework-test-v8-wasix js-astro-ssr-standalone pass

Before the merge, I compared Edge against napi main with and without both fixes:

  • Crashes: across five rounds of the node:vm, node:worker_threads, node:module, node:timers, node:process and node:v8 categories (not in CI), crashes fell from 5–9 per round to 1–2. Crash reports inside PostTaskCommon fell from 13 to 0. No test failed only with the fixes applied.
  • WASIX GC probe: a streamed response under GC pressure finished in 3.5–3.7 s instead of 3.9–4.1 s, with FinalizationRegistry callbacks firing at the same rate.

Notes for reviewers

  • This supersedes chore: update NAPI to merged host JavaScript cleanup #165, which advances napi to bdc85884; that commit is included here.
  • Pre-existing crashes that remain: unofficial_napi_terminate_execution from EdgeWorkerStopAllForEnv during process.exit(), and test-worker-stack-overflow-stack-size.
  • Pre-existing Edge issue, not touched here: when DrainForegroundTasksFromState (src/edge_runtime_platform_v8.cc) returns early on a pending exception, it drops the rest of its batch without calling each task's cleanup. The provider's env release waits for those tasks, so it can hang. I haven't reproduced the hang.

🤖 Generated with Claude Code

Advance the napi submodule from a65e9cb8 to NAPI main at dfc50c75.

- wasmerio/napi#113 stops the V8 provider from touching a foreground
  task after handing it to Edge's enqueue hook. Native Edge crashed in
  PostTaskCommon (SIGSEGV/SIGBUS) when the hook refused a task during
  env cleanup, mostly in vm and worker_threads tests at exit.
- wasmerio/napi#117 runs at most one fallback foreground task per event
  loop checkpoint, so self-reposting GC tasks no longer stall the V8
  WASIX event loop.

The bump also brings wasmerio/napi#87, #88, #90, #91, #92, #103 and
#104. Public header changes are comments only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@syrusakbary
syrusakbary merged commit c81a697 into main Oct 25, 2026
18 checks passed
syrusakbary added a commit that referenced this pull request Oct 27, 2026
Brings in the napi bump with the V8 foreground-task fixes (#170), the
worker termination fix (#171) and the HTTP/2 use-after-free fixes
(#172).

The napi pins conflicted: this branch needs the realm-env provider
(wasmerio/napi#112) and main moved napi forward. napi now points at
e23b3b1, the head of wasmerio/napi#112, which has napi main merged in
and so includes both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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