Skip to content

Native cleanup callbacks erase outer frames from a propagating exception stack #229

Closed

Description

@dimensionscape

A Haxe callback invoked by native RAII cleanup during exception unwinding can clear the runtime's unwinding state. Outer Haxe frames then disappear from CallStack.exceptionStack even though the exception continues through them.

Regression coverage first: test/regression/NativeCleanupExceptionStack, using the existing Main.hx/build.hxml/stdout.txt layout with HXCPP_STACK_TRACE and HXCPP_STACK_LINE. A Haxe wrapper passes a throwing action and an optional nonthrowing cleanup callback to a native helper. Its local C++ guard invokes the cleanup in its destructor. Catch the original exception outside the wrapper and check whether its exception stack includes the wrapper. Run once without cleanup as a control.

Confirmed on Linux x86_64 with Haxe 4.3.3:

control retains wrapper frame: true
cleanup retains wrapper frame: false
cleanup calls: 1

The cleanup callback returns normally. The original exception still reaches its catch; the defect is loss of stack information, not a reproduced crash or swallowed exception.

In include/hx/StackContext.h, pushFrame unconditionally sets mIsUnwindingException=false when a new Haxe function is entered. A cleanup callback can run while native exception unwinding is still active. Returning from that callback does not restore the outer unwinding state. Subsequent popFrame calls therefore stop recording the original exception's outer frames.

Track the state of the active exception unwind across nested calls, or otherwise restore it when a callback entered during cleanup returns. Preserve the separate behavior for a real catch, a new throw and a rethrow. Cover multiple native cleanup callbacks and a callback that catches its own local exception before returning.

This is separate from #63, which covers cppia catch handling. The reproduction uses compiled Haxe and a native C++ scope guard, with no cppia involved. No runtime implementation changes are included.

Activity

  1. added a commit that references this issue on Oct 20, 2026
    31b7a6d
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