diff --git a/crates/wasmedge-sys/src/async/fiber.rs b/crates/wasmedge-sys/src/async/fiber.rs index f08432816..6e562daf0 100644 --- a/crates/wasmedge-sys/src/async/fiber.rs +++ b/crates/wasmedge-sys/src/async/fiber.rs @@ -197,16 +197,17 @@ impl<'a> Future for TimeoutFiberFuture<'a> { in_host: &mut in_host, is_timeout: &mut is_timeout, }; - let r = if setjmp::sigsetjmp(&mut env, 1) == 0 { - crate::executor::JMP_BUF.set(&jmp_state, || { + + let r = crate::executor::JMP_BUF.set(&jmp_state, || { + if setjmp::sigsetjmp(&mut env, 1) == 0 { match self.as_ref().fiber.resume(Ok(())) { Ok(ret) => Poll::Ready(ret), Err(_) => Poll::Pending, } - }) - } else { - Poll::Ready(Err(())) - }; + } else { + Poll::Ready(Err(())) + } + }); libc::timer_delete(timerid); r }) diff --git a/crates/wasmedge-sys/src/executor.rs b/crates/wasmedge-sys/src/executor.rs index 1cd2b020a..0d64930ee 100644 --- a/crates/wasmedge-sys/src/executor.rs +++ b/crates/wasmedge-sys/src/executor.rs @@ -418,8 +418,9 @@ impl Executor { in_host: &mut in_host, is_timeout: &mut is_timeout, }; - if setjmp::sigsetjmp(env, 1) == 0 { - let r = JMP_BUF.set(&jmp_state, || { + + let r = JMP_BUF.set(&jmp_state, || { + if setjmp::sigsetjmp(env, 1) == 0 { check(ffi::WasmEdge_ExecutorInvoke( self.inner.0, func.inner.lock().0 as *const _, @@ -428,17 +429,16 @@ impl Executor { returns.as_mut_ptr(), returns_len, )) - }); - libc::timer_delete(timerid); - r?; - returns.set_len(returns_len as usize); - } else { - libc::timer_delete(timerid); - return Err(Box::new(error::WasmEdgeError::Operation("timeout".into()))); - } - } + } else { + Err(Box::new(error::WasmEdgeError::Operation("timeout".into()))) + } + }); + libc::timer_delete(timerid); + r?; - Ok(returns.into_iter().map(Into::into).collect::>()) + returns.set_len(returns_len as usize); + Ok(returns.into_iter().map(Into::into).collect::>()) + } } /// Asynchronously runs a host function instance and returns the results.