Skip to content

Commit b48b10b

Browse files
authored
Document a caveat regarding max_wasm_stack (#4295)
* Document a caveat regarding `max_wasm_stack` Specifically, that the `max_wasm_stack` only limits the stack that can be consumed by wasm, but it does not guarantee that the so much stack space will be available. * rustfmt * Fix the claim about reseting the stack limit.
1 parent 25a588c commit b48b10b

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

crates/wasmtime/src/config.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,33 @@ impl Config {
494494
/// If a wasm call (or series of nested wasm calls) take more stack space
495495
/// than the `size` specified then a stack overflow trap will be raised.
496496
///
497+
/// Caveat: this knob only limits the stack space consumed by wasm code.
498+
/// More importantly, it does not ensure that this much stack space is
499+
/// available on the calling thread stack. Exhausting the thread stack
500+
/// typically leads to an **abort** of the process.
501+
///
502+
/// Here are some examples of how that could happen:
503+
///
504+
/// - Let's assume this option is set to 2 MiB and then a thread that has
505+
/// a stack with 512 KiB left.
506+
///
507+
/// If wasm code consumes more than 512 KiB then the process will be aborted.
508+
///
509+
/// - Assuming the same conditions, but this time wasm code does not consume
510+
/// any stack but calls into a host function. The host function consumes
511+
/// more than 512 KiB of stack space. The process will be aborted.
512+
///
513+
/// There's another gotcha related to recursive calling into wasm: the stack
514+
/// space consumed by a host function is counted towards this limit. The
515+
/// host functions are not prevented from consuming more than this limit.
516+
/// However, if the host function that used more than this limit and called
517+
/// back into wasm, then the execution will trap immediatelly because of
518+
/// stack overflow.
519+
///
497520
/// When the `async` feature is enabled, this value cannot exceed the
498521
/// `async_stack_size` option. Be careful not to set this value too close
499522
/// to `async_stack_size` as doing so may limit how much stack space
500-
/// is available for host functions. Unlike wasm functions that trap
501-
/// on stack overflow, a host function that overflows the stack will
502-
/// abort the process.
523+
/// is available for host functions.
503524
///
504525
/// By default this option is 512 KiB.
505526
///

0 commit comments

Comments
 (0)