wasi-preview1-component-adapter: repeated invalid I/O reuses closed streams (EBADF becomes EOF/EIO)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 56/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust, wasm
调研方向
Start with crates/wasi-preview1-component-adapter/src/lib.rs around the blocking read and write paths cited in the issue, then trace how Streams caches its input and output streams and how LastOperationFailed is handled. The issue reports a reproducible C program and exact build and run commands; use them to confirm both repeated-call failures. Done means subsequent invalid reads and writes continue returning EBADF, as in the direct P1 output.
由索引模型根据 Issue 内容生成。
描述
wasi-preview1-component-adapter: repeated invalid I/O reuses closed streams (EBADF becomes EOF/EIO)
Summary
On an O_WRONLY descriptor, the second read returns EOF instead of EBADF. On an O_RDONLY descriptor, the second write returns EIO instead of EBADF. No descriptor flags or resource identities change between the two calls.
Confirmed with the standalone C program below, without any custom test driver or trace format. Each lane reproduced the same output 5/5 times in fresh directories on Wasmtime 46.0.0 (Release and Debug), 47.0.2, and 50.0.1. Wasmtime 50.0.1 was the latest upstream release at verification time.
Minimal reproducer (repro.c)
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static void result(const char *operation, ssize_t rv, int error) {
printf("%s: rv=%zd errno=%d (%s)\n", operation, rv, error, strerror(error));
}
int main(void) {
char byte;
int fd = open("file.txt", O_CREAT | O_TRUNC | O_WRONLY, 0644);
printf("initialize: rv=%zd\n", write(fd, "abcdefghijklmnop", 16));
close(fd);
fd = open("file.txt", O_WRONLY);
errno = 0;
ssize_t first = read(fd, &byte, 1);
int first_error = errno;
errno = 0;
ssize_t second = read(fd, &byte, 1);
result("WRONLY read #1", first, first_error);
result("WRONLY read #2", second, errno);
close(fd);
fd = open("file.txt", O_RDONLY);
errno = 0;
first = write(fd, "A", 1);
first_error = errno;
errno = 0;
second = write(fd, "A", 1);
result("RDONLY write #1", first, first_error);
result("RDONLY write #2", second, errno);
close(fd);
return 0;
}
Exact commands
Run in a new empty directory. The first command downloads the official v50.0.1 command adapter; clang, wasm-tools, and wasmtime must be on the stated paths or adjusted to local installations.
curl -fLO https://github.com/bytecodealliance/wasmtime/releases/download/v50.0.1/wasi_snapshot_preview1.command.wasm
/opt/wasi-sdk/bin/clang --target=wasm32-wasip1 -std=c17 -O2 -Wall -Wextra -Werror repro_rc1_closed_stream_reuse.c -o repro_p1.wasm
wasm-tools component new repro_p1.wasm --adapt wasi_snapshot_preview1=wasi_snapshot_preview1.command.wasm -o repro_adapter.wasm
wasmtime run --dir . repro_p1.wasm; wasmtime run --dir . repro_adapter.wasm
Expected vs. actual output (Wasmtime 50.0.1)
Direct P1 (expected):
initialize: rv=16
WRONLY read #1: rv=-1 errno=8 (Bad file descriptor)
WRONLY read #2: rv=-1 errno=8 (Bad file descriptor)
RDONLY write #1: rv=-1 errno=8 (Bad file descriptor)
RDONLY write #2: rv=-1 errno=8 (Bad file descriptor)
Adapter P2 (actual):
initialize: rv=16
WRONLY read #1: rv=-1 errno=8 (Bad file descriptor)
WRONLY read #2: rv=0 errno=0 (Success)
RDONLY write #1: rv=-1 errno=8 (Bad file descriptor)
RDONLY write #2: rv=-1 errno=29 (I/O error)
Root cause
Streams retains the InputStream/OutputStream in OnceCell. After the first real I/O error, the host changes the stream to Closed and returns LastOperationFailed(EBADF) (read path, write path). The adapter returns EBADF for that call but leaves the closed stream cached.
The next call observes only Closed: blocking read maps it to an empty vector/EOF (lib.rs:2601-2604), while blocking write maps it to ERRNO_IO (lib.rs:2629-2635). The same source paths are present in v50.0.1.
Suggested fix and causal evidence
Invalidate the corresponding cached stream when LastOperationFailed is returned, so the next P1 operation recreates the stream and rechecks the descriptor. A minimal v46 experiment did this for both read and write. In patch/revert testing, both divergences changed 3/3 → 0/3 → 3/3; reverting restored the original adapter binary. This was a causal experiment, not a proposed complete production patch.
- 主要语言
- Rust
- 星标
- 18.9k
- 派生
- 2k
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 238
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bytecodealliance/wasmtime 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
bytecodealliance/wasmtime#15536 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
bytecodealliance/wasmtime#15455 · 1 条评论 ·
维护者通常 1 天内回复
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale reads可能已有人在做 @dpfens 于 13 天前认领。 未关闭wasi
难度 2/5 1-3 小时 新手友好度 72/100
bytecodealliance/wasmtime#15296 ·
维护者通常 1 天内回复
-
bug wasm-proposal:exceptions wasmtime:debugging
难度 2/5 1-3 小时 新手友好度 76/100
bytecodealliance/wasmtime#14102 ·
维护者通常 1 天内回复
-
wasm-proposal:gc
难度 2/5 1-3 小时 新手友好度 62/100
bytecodealliance/wasmtime#13808 · 2 条评论 ·
维护者通常 1 天内回复
查看 bytecodealliance/wasmtime 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
area: plugins bug
难度 2/5 1-3 小时 新手友好度 72/100
clipy-recorder/clipy#1039 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
valkey-io/valkey-glide#7975 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
gofractally/psibase#2379 ·
维护者通常 3 天内回复
-
Qwen stream parser: a chunk with "error": null is treated as a stream error可能已有人在做 @Beehtrix 今天认领。 未关闭area:models bug good first issue
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 2 天内回复