Skip to content

Commit

Permalink
runtime: Add env var for maximum stack size
Browse files Browse the repository at this point in the history
  • Loading branch information
evaporei committed Aug 19, 2021
1 parent 4c3a986 commit fea87c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ those.
corresponds to 1GB.
- `GRAPH_QUERY_CACHE_STALE_PERIOD`: Number of queries after which a cache
entry can be considered stale. Defaults to 100.
- `GRAPH_MAX_API_VERSION`: Maximum `apiVersion` supported, if a developer tries to create a subgraph
with a higher `apiVersion` than this in their mappings, they'll receive an error. Defaults to `0.0.5`.
- `GRAPH_RUNTIME_MAX_STACK_SIZE`: Maximum stack size for the WASM runtime, if exceeded the execution
stops and an error is thrown. Defaults to 512KiB.

## GraphQL

Expand Down
11 changes: 11 additions & 0 deletions runtime/wasm/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ use std::collections::BTreeMap;
use std::sync::Arc;
use std::thread;

const ONE_MIB: usize = 1 << 20; // 1_048_576

lazy_static! {
/// Verbose logging of mapping inputs
pub static ref LOG_TRIGGER_DATA: bool = std::env::var("GRAPH_LOG_TRIGGER_DATA").is_ok();

/// Maximum stack size for the WASM runtime
pub static ref MAX_STACK_SIZE: usize = std::env::var("GRAPH_RUNTIME_MAX_STACK_SIZE")
.ok()
.and_then(|max_stack_size| max_stack_size.parse().ok())
// 512KiB
.unwrap_or(ONE_MIB / 2);
}

/// Spawn a wasm module in its own thread.
Expand Down Expand Up @@ -140,6 +149,8 @@ impl ValidModule {
config.interruptable(true); // For timeouts.
config.cranelift_nan_canonicalization(true); // For NaN determinism.
config.cranelift_opt_level(wasmtime::OptLevel::None);
config.max_wasm_stack(*MAX_STACK_SIZE).unwrap();

let engine = &wasmtime::Engine::new(&config)?;
let module = wasmtime::Module::from_binary(&engine, raw_module)?;

Expand Down

0 comments on commit fea87c0

Please sign in to comment.