Repository navigation
Conversation
A `ReadableStream` backed by a file resource (`Deno.FsFile.readable`) could not be cancelled while a read was in flight. Reads on pipes / FIFOs may block in the kernel indefinitely, so the in-flight `op_read` kept the runtime alive long after JS had finished. Add a `CancelHandle` to `FileResource`, wrap `read` / `read_byob` with `try_or_cancel`, and trigger the handle from `Resource::close()`. Fixes #21186. Co-Authored-By: Divy Srivastava <me@littledivy.com>
Contributor
Author
|
Closing as duplicate — orchid pre-created #34544 from the same branch; consolidating discussion there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A
ReadableStreambacked by a file resource (Deno.FsFile.readable) could not be cancelled while a read was in flight. Reads on pipes / FIFOs may block in the kernel indefinitely, so the in-flightop_readkept the runtime alive long after JS had finished, preventing the process from exiting.This PR adds a
CancelHandletoFileResource, wrapsread/read_byobwithtry_or_cancel, and triggers the handle fromResource::close(). The op completes promptly on the JS side when the stream is cancelled; the spawned blocking thread may still complete its own kernel read (we cannot interruptspawn_blocking), but its result is discarded and the runtime no longer waits on it.This mirrors the pattern already used by
ChildStdoutResource,TcpStreamResource, etc.Fixes #21186.
Reproducer
Before the fix, this would print
OKand then hang indefinitely:After the fix, the same script prints
OKand exits cleanly.Test plan
readableStreamCancelOnFifointests/unit/files_test.ts(Unix only): spawns a subprocess that performs the above, with a 10s watchdog. Verified it fails onmainand passes with this PR.readableStream/readableStreamTextEncoderPipetests still pass.cargo clippy -p deno_ioclean.Closes denoland/orchid#288