Skip to content

Add timeout trap support#6

Merged
chaploud merged 6 commits intoclojurewasm:mainfrom
DeanoC:deano/spider-timeout-support
Mar 11, 2026
Merged

Add timeout trap support#6
chaploud merged 6 commits intoclojurewasm:mainfrom
DeanoC:deano/spider-timeout-support

Conversation

@DeanoC
Copy link
Contributor

@DeanoC DeanoC commented Mar 8, 2026

Summary

  • add a TimeoutExceeded trap/error for deadline-based interruption
  • thread timeout reporting into the CLI error formatter
  • provide the runtime support needed for embedded Spider WASM execution limits

Validation

  • zig build test

DeanoC and others added 6 commits March 8, 2026 18:44
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).
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
@chaploud chaploud self-requested a review March 11, 2026 12:11
Copy link
Contributor

@chaploud chaploud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@DeanoC
Copy link
Contributor Author

DeanoC commented Mar 11, 2026

@chaploud I pulled eature/timeout-support into this branch and pushed the updated PR head at 2412b97. The branch now includes the --timeout CLI flag, deadline-aware JIT suppression, and the added timeout tests. Could you take another look?

Copy link
Contributor

@chaploud chaploud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good — I've confirmed the branch matches feature/timeout-support exactly. Merging now. Thanks for the quick turnaround!

@chaploud chaploud merged commit c4b9196 into clojurewasm:main Mar 11, 2026
3 of 4 checks passed
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.

2 participants