Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/compiler/src/engine/trap/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use wasmer_vm::Trap;
pub fn get_trace_and_trapcode(trap: &Trap) -> (Vec<FrameInfo>, Option<TrapCode>) {
let info = FRAME_INFO.read().unwrap();
match &trap {
// A user error
Trap::User(_err) => (wasm_trace(&info, None, &Backtrace::new_unresolved()), None),
// A user error — skip backtrace to avoid _Unwind_Backtrace lock contention
Trap::User(_err) => (Vec::new(), None),
// A trap caused by the VM being Out of Memory
Trap::OOM { backtrace } => (wasm_trace(&info, None, backtrace), None),
// A trap caused by an error on the generated machine code for a Wasm function
Expand Down
8 changes: 2 additions & 6 deletions lib/vm/src/trap/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,17 @@ impl Trap {
}

/// Construct a new Wasm trap with the given trap code.
///
/// Internally saves a backtrace when constructed.
pub fn lib(trap_code: TrapCode) -> Self {
let backtrace = Backtrace::new_unresolved();
let backtrace = Backtrace::from(vec![]);
Self::Lib {
trap_code,
backtrace,
}
}

/// Construct a new OOM trap with the given source location and trap code.
///
/// Internally saves a backtrace when constructed.
pub fn oom() -> Self {
let backtrace = Backtrace::new_unresolved();
let backtrace = Backtrace::from(vec![]);
Self::OOM { backtrace }
}

Expand Down
18 changes: 8 additions & 10 deletions lib/vm/src/trap/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,17 +843,15 @@ impl<T> TrapHandlerContextInner<T> {
})
});

// Don't try to generate a backtrace for stack overflows: unwinding
// information is often not precise enough to properly describe what is
// happenning during a function prologue, which can lead the unwinder to
// read invalid memory addresses.
// Skip backtrace capture entirely. Backtrace::new_unresolved() calls
// _Unwind_Backtrace which invokes _Unwind_Find_FDE for each frame,
// taking a process-wide mutex (object_mutex in libgcc or dl_iterate_phdr
// in glibc). Under high concurrency this causes severe lock contention
// (observed: 67% of CPU in native_queued_spin_lock_slowpath).
//
// See: https://github.com/rust-lang/backtrace-rs/pull/357
let backtrace = if signal_trap == Some(TrapCode::StackOverflow) {
Backtrace::from(vec![])
} else {
Backtrace::new_unresolved()
};
// The WASM-level stack trace (FrameInfo) derived from the backtrace
// is lost, but the trap code and error message are preserved.
let backtrace = Backtrace::from(vec![]);

// Set up the register state for exception return to force the
// coroutine to return to its caller with UnwindReason::WasmTrap.
Expand Down
Loading