Repository navigation
fs: keep readFile abortable on non-regular files - #66940
Open
christianaurichzm wants to merge 1 commit into
Open
christianaurichzm wants to merge 1 commit into
christianaurichzm wants to merge 1 commit into
Conversation
`ReadFileJob` treats a file that is not a regular file as size 0 and reads it to EOF inside one thread pool job, so the `AbortSignal` is only checked once the job ends. `fs.readFile()` and `fs.promises.readFile()` on a FIFO whose writer stays open therefore do not settle until the writer closes, and on `/dev/zero` they keep growing the buffer until the process runs out of memory. Hand the fd back to the chunked reader for non-regular files, the path files larger than one chunk already take. It checks the signal before each read. Regular files that report size 0, such as procfs files, are still read in one job. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66940 +/- ##
==========================================
+ Coverage 90.57% 90.59% +0.01%
==========================================
Files 797 797
Lines 278502 278278 -224
Branches 53538 53504 -34
==========================================
- Hits 252267 252106 -161
+ Misses 16576 16542 -34
+ Partials 9659 9630 -29
🚀 New features to boost your workflow:
|
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.
fs.readFile()andfs.promises.readFile()ignore anAbortSignalon FIFOs and devices. The read only ends at EOF, so on a FIFO whose writer stays open the abort waits for the writer to close, and on/dev/zeroit never ends:v22.23.1 prints
AbortErrorafter 100 ms. Onmainit never does, and memory grows until the process is killed (after 1 s with a 2 GiB limit).Since #65327,
ReadFileJobreads a non-regular file to EOF in one thread pool job and only checks the signal when the job is done. Files over one chunk already go back to the chunked reader, which checks it before each read. Send non-regular files there as well. Regular files that report size 0, like the ones in procfs, are still read in one job. Only v26.8.0+ is affected.The new test aborts a read on a FIFO and checks that the reader closes it while the writer is still open. It fails on
mainfor both APIs and passes with the fix. fs tests, C++ lint/format and ESLint pass on Linux x64.Refs: #65327