Skip to content

fix(wasm): give a plugin's config write a fresh budget, and name alloc failures - #246

Open
ndreno wants to merge 1 commit into
mainfrom
fix/wasm-init-budget
Open

ndreno wants to merge 1 commit into
mainfrom
fix/wasm-init-budget

Conversation

@ndreno

@ndreno ndreno commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Summary

The full-coverage run on main (ba339c7) failed once in test_jwt_auth_invalid_issuer: the request got 500 instead of 401, and the gateway logged

failed to get middleware 'jwt-auth': WASM execution trapped: alloc failed: error while executing at wasm backtrace: 0: barbacane_jwt_auth.wasm!alloc

The same commit passed on the scheduled run. The log shows no cause for the trap, and reading the code turned up two defects:

  1. init writes the config on a leftover budget. PluginInstance::init calls write_to_memory, which runs the guest's alloc, before resetting fuel and the epoch deadline. The store's budget is set at creation and instantiation spends from it, so alloc gets whatever is left. Under a slow, coverage-instrumented build, instantiation can come close to the deadline, and alloc is then interrupted. The per-request path (call_with_body) already resets the budget before its write; only init didn't.
  2. alloc errors lose their cause. They were wrapped as alloc failed: {e}, which prints only wasmtime's backtrace header. Every other call goes through call_error, which names out of fuel, timeout or the trap.

I can't prove (1) is what happened on CI, because (2) hid the cause. With this change, a recurrence would say which limit it hit.

Changes

  • crates/barbacane-wasm/src/instance.rs:
    • New reset_budget(), called before the config write and again before the guest's init.
    • alloc errors go through call_error, with the fuel the call actually had.
  • CHANGELOG: an entry under Fixed.

Testing

Four new tests, each failing without the change (4 of 20 in instance::tests go red):

  • init succeeds after instantiation spent all fuel (set_fuel(0)), and after the deadline passed (1 tick, then a 20 ms sleep).
  • A runaway alloc reports "out of fuel", and an alloc that hits unreachable keeps that cause.

cargo test -p barbacane-wasm: 250 pass. cargo clippy -p barbacane-wasm --lib --bins is clean.

…c failures

PluginInstance::init wrote the config through the guest's `alloc` before
resetting fuel and the epoch deadline, so `alloc` ran on whatever the
store had left after instantiation, which spends from the same budget
from store creation on. A slow instantiation could leave too little, and
the route answered 500 with "failed to get middleware". The per-request
path already reset the budget before its write; init now does the same.

`alloc` errors were wrapped as "alloc failed: <backtrace header>", which
drops the trap reason. They now go through call_error like every other
call, so running out of fuel, a timeout and other traps are named.

Four tests, each failing without the change: init succeeds after
instantiation spent all fuel and after the deadline passed, a runaway
alloc reports "out of fuel", and an `unreachable` in alloc keeps its
cause.

Signed-off-by: Nicolas Dreno <nicolas.dreno@barbacane.dev>
@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • deep-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: barbacane-dev/barbacane/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 69177531-c939-427f-830f-aa18867c08b6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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