Conversation
JIT-compiled native code does not call consumeInstructionBudget(), so fuel checks were silently bypassed for hot functions. This caused infinite loops to hang even with --fuel set to a finite value. Add jitSuppressed() check at all 6 JIT gate locations (compilation, execution, back-edge OSR) in doCallDirect, executeRegIR, and executePredecoded. Zero performance impact on normal execution (fuel=null → jitSuppressed() returns false). Test: 30_infinite_loop.wasm with fuel=1M now correctly exhausts.
JIT-compiled code bypassed fuel checks, causing infinite loops to hang with --fuel set. All 6 JIT gates now check jitSuppressed(). Mac+Ubuntu Merge Gate passed (spec 62263/0, e2e 792/0, compat 50/0).
# Conflicts: # src/vm.zig
Based on DeanoC's PR clojurewasm#6 timeout trap support (merged in previous commit). Additions: - --timeout <ms> CLI option (mirrors --fuel pattern) - jitSuppressed() now also checks deadline_ns (JIT bypass fix) - 3 tests: expired deadline, infinite loop timeout, API behavior
There was a problem hiding this comment.
Hi @DeanoC, thank you for this contribution! The consumeInstructionBudget() design that unifies fuel + deadline checks is clean and well thought out.
While testing your changes, I discovered a pre-existing bug: JIT-compiled native code bypasses both fuel and deadline checks entirely. When a function gets hot enough for JIT compilation, consumeInstructionBudget() never runs. I've fixed the fuel side on main by suppressing JIT when resource limits are active (jitSuppressed()). (A proper fix (inserting fuel/deadline checks at JIT back-edges, à la wasmtime) is planned as a future improvement.)
Your PR was missing tests and a CLI option, so I've built on top of your changes in a branch that includes everything:
https://github.com/clojurewasm/zwasm/tree/feature/timeout-support
--timeout <ms>CLI option (mirrors--fuel)- JIT suppression extended to cover deadline
- 3 tests (expired deadline, infinite loop timeout, API behavior)
- All gates pass on Mac + Ubuntu (spec 62,263/0, e2e 792/0, compat 50/0)
Could you pull feature/timeout-support into your fork's branch, then re-request review? That way the commit history properly credits you as the original author.
Alternatively, I can merge feature/timeout-support directly — your original commit (62fe06f) is preserved in the merge history either way.
Thanks again!
chaploud
left a comment
There was a problem hiding this comment.
Looks good — I've confirmed the branch matches feature/timeout-support exactly. Merging now. Thanks for the quick turnaround!
Summary
TimeoutExceededtrap/error for deadline-based interruptionValidation