Repository navigation
Description
Summary
Fix Windows async stack overflow so it produces the same controlled runtime diagnostic as Darwin/Linux instead of a raw Windows exception. The current test is intentionally skipped on Windows after GitHub comment 2026-06-09T21:49:06Z, but the skip is only a paper-over until the async backend migration can provide a real Windows-safe stack overflow path.
Spec
§14.2 says each fiber has a real stack. §14.19 says fiber stacks have guard-page overflow detection where the platform supports it, and stack overflow must be diagnosed by the runtime rather than escaping as undefined process failure. The behavior fixture expects:
exit 134
stderr contains "fiber stack overflow"
Current state
test/behavior/behav_async_stack_overflow.w still encodes the desired behavior with //! expect-exit: 134 and //! expect-stderr: fiber stack overflow, but now has //! skip-windows for issue #369 (test/behavior/behav_async_stack_overflow.w:1). The original issue records native Windows failure as exit code -1073741819 and explains that a VirtualProtect(PAGE_NOACCESS) / VEH attempt could not run because the exception handler uses the exhausted current stack.
The fiber cores are platform-specific. Windows has a fixed FIBER_STACK_SIZE and FIBER_ALT_STACK_SIZE (rt/fiber_core_windows.w:26, rt/fiber_core_windows.w:61), installs stack overflow handlers through rt_fiber_install_signal_handlers (rt/fiber_core_windows.w:453), and records current-fiber stack metadata (rt/fiber_core_windows.w:437). Darwin has the parallel substrate (rt/fiber_core_darwin.w:27, rt/fiber_core_darwin.w:454). The async backend migration plan explicitly calls for replacing direct fiber_core_* calls with a backend interface in docs/async-proposal.md.
Implementation plan
- Implement this as part of the async backend split in
docs/async-proposal.md, not as another local VEH patch. Add a Windows backend abstraction that can detect guard-page stack overflow on a usable handler stack. - In
rt/fiber_core_windows.w, separate stack allocation/protection from scheduler bookkeeping so the backend can install either fibers/ucontext-equivalent guard handling or a Windows-specific trampoline with a known-safe emergency stack. - Preserve the existing runtime diagnostic surface: route the detected overflow to the same path that emits
fiber stack overflowand exits 134 on non-Windows. - Remove the
//! skip-windowsdirective fromtest/behavior/behav_async_stack_overflow.wonly after native Windows produces the controlled diagnostic. - Do not solve this by increasing
FIBER_STACK_SIZE, increasing the compiler executable stack reserve, or accepting Windows raw exception codes. Those are symptom workarounds. - Document the Windows backend behavior in
docs/async-proposal.mdor the runtime source comments so future guard-page changes do not reintroduce current-stack VEH assumptions.
Test plan
Run with test test/behavior/behav_async_stack_overflow.w on native Windows and non-Windows hosts.
Add a Windows-specific regression note in the fixture once the skip is removed, keeping //! expect-exit: 134 and //! expect-stderr: fiber stack overflow.
Run the existing Windows async cancellation tests, especially test/behavior/behav_async_cancel.w, test/behavior/behav_async_cancel_nested_unwind.w, and test/behavior/behav_async_cancel_await_cleans_children.w.
Acceptance criteria
- Native Windows no longer skips
test/behavior/behav_async_stack_overflow.w. - Stack overflow exits 134 and stderr contains
fiber stack overflow. - Normal fiber stack size and compiler stack reserve are not increased as a workaround.
- Existing async cancellation and panic tests remain green.
with build && with build :fixpoint && with build :testpass on the affected platforms.
Dependencies
Depends on the async backend migration in docs/async-proposal.md.
Activity
ehartford commentedon Jun 9, 2026
Temporary paper-over landed in 768af7e: the test runner now supports a narrow //! skip-windows:\ directive, and only \ est/behavior/behav_async_stack_overflow.w\ uses it. The test still keeps \expect-exit: 134\ and \expect-stderr: fiber stack overflow\ for non-Windows platforms. This keeps #369 open for the real fix via the async backend migration in \docs/async-proposal.md; it does not accept raw Windows \
ehartford commentedon Jul 16, 2026
Blocked on #676 (minicoro fiber-backend migration, per docs/feature_plans/async-proposal.md): the Windows async stack-overflow diagnostic should be implemented against minicoro's Windows backend, not the current Darwin-only backend. Both are milestone post-v0.16.0.
ropoctl commentedon Aug 17, 2026
Root cause pinned (native Windows x86_64), so a future implementer has the exact entry point.
The diagnostic path itself exists:
rt/fiber_core_windows.w:462with_fiber_stack_overflow_handlerchecks the fault address against the fiber's guard page and writes"fatal: fiber stack overflow (fiber #...". It is registered atfiber_core_windows.w:481viart_fiber_install_signal_handlers(...).The gap: that install hook is a no-op stub on Windows.
rt/windows_x86_64.w:384:The handler is modeled on POSIX signals (
sig: i32, fault addr from a ucontext), copied fromfiber_core_darwin.w. Windows delivers a guard-page fault as an SEH exception (STATUS_GUARD_PAGE_VIOLATION/EXCEPTION_ACCESS_VIOLATION0xC0000005), not a signal — so with nothing installed, a fiber overflow crashes via the default unhandled-exception path. Neither the diagnostic nor the exit-134 convention is produced, which is exactly whattest/behavior/behav_async_stack_overflow.wasserts (expect-stderr: fiber stack overflow,expect-exit: 134).Secondary:
allocate_stack_region(fiber_core_windows.w:363) rt_mmapspage_sz + sizeand returnsregion + page_sz, but neverVirtualProtects the reserved guard page toPAGE_NOACCESS/PAGE_GUARD, so the guard isn't armed on Windows either.Fix outline (own scoped task; isolated batch + drop-audit + native VM verify):
VirtualProtectthe guard pagePAGE_NOACCESS(orPAGE_GUARD) inallocate_stack_region.rt_fiber_install_signal_handlerson Windows viaAddVectoredExceptionHandler.EXCEPTION_POINTERS→ fault address, match it against the faulting fiber's guard page, write the diagnostic, exit 134.The behavior test stays
skip-windowsunder this issue until (1)-(3) land — the skip is a genuine feature gap, not a stale gate.Windows: fiber stack-overflow diagnostic via vectored exception handl…
test(windows): re-skip async fiber stack-overflow diagnostic (#369)
Windows: fiber stack-overflow diagnostic + un-skip its test (#369)
Windows: fiber stack-overflow diagnostic + un-skip its test (#369)
Merge pull request #907 from withlang-dev/fix-369-fiber-stack-overflow
Merge pull request #917 from withlang-dev/reland-fiber-369
Windows: fiber stack-overflow diagnostic + un-skip its test (withlang…