deno: Deno.run with piped stdout gets stuck in specific scenarios
Reproduction
- Generate test file:
echo "hello world" > file.txt
for i in {1..10}; do cat file.txt file.txt > file2.txt && mv file2.txt file.txt; done
- create test.js
const proc = Deno.run({
cmd: ["cat", "test.json"],
stdout: "piped",
stderr: "piped"
});
const status = await proc.status();
- run test.ts
deno --allow-run test.js
- Deno gets stuck on
await proc.status().
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 18 (13 by maintainers)
Commits related to this issue
- Workaround denoland/deno#4568 — committed to lucacasonato/deno_lint by lucacasonato 4 years ago
- Workaround denoland/deno#4568 — committed to lucacasonato/deno_lint by lucacasonato 4 years ago
encountered same issue again! here is my work around:
I just ran into this again on the registry. It is a very annoying bug because it is so not logical. I think many people have and will run into it. I also ran into it for doc.deno.land. We should really address this one soon.
This happens when the stdout is bigger than (?) 64KiB, consider:
You have to uncomment the
// drain the stdout hereline to make the Wikipedia link work. Tested on Windows. Run withdeno run --allow-run test.js.So after further investigation I think this works as it should.
stdoutandstderrpipes should be closed manually before awaiting on the status, so @rok-star’s solution is the preferable one for the time being. I will update the docs for theDeno.runAPI accordingly (edit: https://github.com/denoland/deno/pull/9390), but overall the API is not very user-friendly and I think it might have to undergo a rework for 2.0 to make it more like Tokio’sChildAPI (I will open a separate issue for it).@ebebbington this should no longer be the case, calling
p.status()will closestdinof the child process before awaiting on the status to avoid the deadlock (https://docs.rs/tokio/1.1.1/tokio/process/struct.Child.html#method.wait).Still happening on latest canary
Everything works as expected when I add
await proc.output()between the run call and theproc.status()call.await proc.stderrOutput()has no effect.