Skip to content

bug(find): unwrap() panic / wasm trap on EPIPE when piped to head (WASI target) #801

Closed

Description

@aki-kong

Hi team,

I have a use case where I'm running find under wasip1 (wazero / wasmtime) runtime.

Reproduction

wasmtime run --dir . find.wasm . | head -5

Expectation

.
./.git
./.git/hooks
./.git/hooks/applypatch-msg.sample
./.git/hooks/commit-msg.sample

Actual

wasmtime output

.
./.git
./.git/hooks
./.git/hooks/applypatch-msg.sample
./.git/hooks/commit-msg.sample
Error: failed to run main module `find.wasm`

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
    0: 0x11053e - find-dea9546337a705a1.wasm!abort
    1:  0xe00b7 - find-dea9546337a705a1.wasm!std[5051f54ad3814dbd]::sys::pal::wasi::abort_internal
    2:  0xdd285 - find-dea9546337a705a1.wasm!std[5051f54ad3814dbd]::process::abort
    3:  0xdd654 - find-dea9546337a705a1.wasm!__rustc[8068f81614cfe5c]::__rust_abort
    4:  0xdd64a - find-dea9546337a705a1.wasm!__rustc[8068f81614cfe5c]::rust_panic
    5:  0xdc941 - find-dea9546337a705a1.wasm!std[5051f54ad3814dbd]::panicking::panic_with_hook
    6:  0xdc32f - find-dea9546337a705a1.wasm!std[5051f54ad3814dbd]::panicking::panic_handler::{closure#0}
    7:  0xdc293 - find-dea9546337a705a1.wasm!std[5051f54ad3814dbd]::sys::backtrace::__rust_end_short_backtrace::<std[5051f54ad3814dbd]::panicking::panic_handler::{closure#0}, !>
    8:  0xdd68d - find-dea9546337a705a1.wasm!__rustc[8068f81614cfe5c]::rust_begin_unwind
    9:  0x23fa0 - find-dea9546337a705a1.wasm!core[fa2af07491efb8b4]::panicking::panic_fmt
   10:  0x274a4 - find-dea9546337a705a1.wasm!core[fa2af07491efb8b4]::result::unwrap_failed
   11:  0x3b4c3 - find-dea9546337a705a1.wasm!<findutils::find::matchers::printer::Printer as findutils::find::matchers::Matcher>::matches::hae771739706bc70d
   12:  0x31006 - find-dea9546337a705a1.wasm!<findutils::find::matchers::logical_matchers::AndMatcher as findutils::find::matchers::Matcher>::matches::hb875199c9924eabf
   13:  0x48ba0 - find-dea9546337a705a1.wasm!findutils::find::find_main::haef4c91fee922d49
   14:  0x2a5f8 - find-dea9546337a705a1.wasm!find::main::h062fa23da3704f33
   15:  0x2a523 - find-dea9546337a705a1.wasm!std::sys::backtrace::__rust_begin_short_backtrace::hfd0f6a168738c922
   16:  0x2a76c - find-dea9546337a705a1.wasm!__main_void
   17:   0x1273 - find-dea9546337a705a1.wasm!_start
    2: wasm trap: wasm `unreachable` instruction executed

Ouput from the wazero based Go program:

.
./.git
./.git/hooks
./.git/hooks/applypatch-msg.sample
./.git/hooks/commit-msg.sample

thread 'main' (1) panicked at src/find/matchers/printer.rs:67:21:
called `Result::unwrap()` on an `Err` value: Os { code: 29, kind: Uncategorized, message: "I/O error" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
module[] function[_start] failed: wasm error: unreachable
wasm stack trace:
	find-dea9546337a705a1.wasm.abort()
	find-dea9546337a705a1.wasm._RNvNtNtNtCs6TxCtTcuIIP_3std3sys3pal4wasi14abort_internal.llvm.7521258323505191217()
	find-dea9546337a705a1.wasm._RNvNtCs6TxCtTcuIIP_3std7process5abort()
	find-dea9546337a705a1.wasm._RNvCsGIExRX8pES_7___rustc12___rust_abort()
	find-dea9546337a705a1.wasm._RNvCsGIExRX8pES_7___rustc10rust_panic(i32,i32)
	find-dea9546337a705a1.wasm._RNvNtCs6TxCtTcuIIP_3std9panicking15panic_with_hook(i32,i32,i32,i32,i32)
	find-dea9546337a705a1.wasm._RNCNvNtCs6TxCtTcuIIP_3std9panicking13panic_handler0B5_(i32)
	find-dea9546337a705a1.wasm._RINvNtNtCs6TxCtTcuIIP_3std3sys9backtrace26___rust_end_short_backtraceNCNvNtB6_9panicking13panic_handler0zEB6_(i32)
	find-dea9546337a705a1.wasm._RNvCsGIExRX8pES_7___rustc17rust_begin_unwind(i32)
	find-dea9546337a705a1.wasm._RNvNtCsltDuuzhejvA_4core9panicking9panic_fmt(i32,i32,i32)
	find-dea9546337a705a1.wasm._RNvNtCsltDuuzhejvA_4core6result13unwrap_failed(i32,i32,i32,i32,i32)
	find-dea9546337a705a1.wasm._ZN98_..find..matchers..printer..Printer..find..matchers..Matcher(i32,i32,i32) i32
	find-dea9546337a705a1.wasm._ZN110_..find..matchers..logical_matchers..AndMatcher..find..matchers..Matcher(i32,i32,i32) i32
	find-dea9546337a705a1.wasm._ZN9findutils4find9find_main17haef4c91fee922d49E(i32,i32,i32,i32) i32
	find-dea9546337a705a1.wasm._ZN4find4main17h062fa23da3704f33E()
	find-dea9546337a705a1.wasm._ZN3std3sys9backtrace28__rust_begin_short_backtrace17hfd0f6a168738c922E(i32)
	find-dea9546337a705a1.wasm.__main_void() i32
	find-dea9546337a705a1.wasm._start()

Slight difference in the error as the error surfacing is a little different.

wasmtime -> Catches the actual SIGPIPE -> find.wasm writes again -> gets a EPIPE -> panics -> std::process::abort() -> wasm code unreachable.

wazero package -> writes return a EOF -> surfaces as I/O error in find.

Fix

Treat ErrorKind::BrokenPipe as std::process::exit(0) instead of unwrapping.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions