spawn_local panics when called from a sync export (regression in 0.63.0)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Start by reading the spawn_local implementation and the change in #1721 that added the assert!(!task.is_null()); the report ties the regression to calls from sync exports with the async-spawn feature. Check the reproduction and failing tests linked from componentized/http#36, then trace how sync exports schedule work and how async exports run the SPAWNED queue. Done means the supported behavior or limitation is clear and covered by a regression test.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
As of 0.63.0, calling wit_bindgen::spawn_local from a sync export traps with wasm unreachable instruction executed. The panic comes from assert!(!task.is_null()) added in #1721. On 0.62.0 the same code worked: the spawned future went onto the SPAWNED queue and the next async export's executor ran it.
We have a component that exports wasi:http/[email protected] and wraps the host's imported wasi:http/types, logging each call. Several functions in that interface are sync in WIT but take or return futures carrying resources. For example, request.new takes trailers: future<result<option<trailers>, error-code>>. Our exported trailers resource wraps the imported one, so we need a task that waits on the incoming future, converts the resource, and writes the result to a new future:
fn new(
headers: Headers,
contents: Option<StreamReader<u8>>,
trailers: FutureReader<Result<Option<Trailers>, ErrorCode>>,
options: Option<RequestOptions>,
) -> (Request, FutureReader<Result<(), ErrorCode>>) {
let headers = headers.into_inner::<TraceFields>().fields;
let (trailers_tx, trailers_rx) = wit_future::new(|| Ok(None));
wit_bindgen::spawn_local(async move { // <- panics in 0.63.0
let trailers = match trailers.await {
Ok(Some(t)) => Ok(Some(t.into_inner::<TraceFields>().fields)),
Ok(None) => Ok(None),
Err(e) => Err(e),
};
let _ = trailers_tx.write(trailers).await;
});
let (request, read) = types::Request::new(headers, contents, trailers_rx, options);
(Request::new(Self::new(request)), read)
}
request.consume-body, response.new and response.consume-body follow the same pattern. The crate is built with the async-spawn feature and uses a single wit-bindgen version.
Observed (0.63.0, wasmtime 49.0.3)
Error: error while executing at wasm backtrace:
...
5: core::panicking::panic_fmt
6: core::panicking::panic
7: trace.wasm!wasi:http/[email protected]#[static]request.new
Caused by:
wasm trap: wasm `unreachable` instruction executed
Expected
A supported way to start background work from a sync export. Minimally, display a clear error that says this isn't supported, such as "spawn_local called outside of an async export"? Right now the user sees only a bare unreachable trap.
I know our use of the 0.62 behavior was fragile. The spawned task only ran if an async export happened to run later in the same instance. A component that exports only wasi:http/types never ran it, so its futures never resolved.
Questions
- Is there a supported way to adapt futures or streams in a sync export? This is unavoidable for any component that exports
wasi:http/typesand wraps resources. - If spawning from a sync export can't be supported, could
spawn_localfall back to the oldSPAWNEDqueue when no task is set? - Is there a pattern you'd recommend instead, for example an option to export sync-typed WIT functions with the async ABI?
Full reproduction: componentized/http#36 (the wit-bindgen 0.62 → 0.63 bump), failing tests in components/trace*.
- Ngôn ngữ chính
- Rust
- Star
- 1.5k
- Fork
- 306
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 21
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bytecodealliance/wit-bindgen
-
gen-rust
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bytecodealliance/wit-bindgen#1791 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
gen-rust
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
bytecodealliance/wit-bindgen#1790 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Document build.rs approachĐang mởgen-rust
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 55/100
bytecodealliance/wit-bindgen#1787 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
gen-c#
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
bytecodealliance/wit-bindgen#1759 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Async exports never free the block of indirect parametersCó thể đã có người làm @Aditya1404Sal đã nhận 37 ngày trước. Đang mởasync
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
bytecodealliance/wit-bindgen#1757 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bytecodealliance/wit-bindgen
Issue tương tự
-
lane:collections todo:ticket
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 3 ngày
-
bugfix
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
storytold/designcraft#3662 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue tooling
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Nixitov/Riptide-Native#521 ·
Maintainer thường phản hồi trong vòng 1 ngày