-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime): "Error: EOF: end of file, read" on Windows (#2238)
NodeJS makes it unsafe to perform syncrhonous (aka blocking) operations on file descriptors 0 through 2 (STDIN, STDOUT, STDERR), as those are set to `O_NONBLOCK` by `libuv`. This is particularly problematic on Windows where there is no easy way to re-open those in blocking mode. Consequently, we must handle some quirks in cases where blocking attempts result in conditions typical of non-blocking access: `EAGAIN` errors must be caught and retried, and `EOF` errors must be "ignored". This PR adds the necessary code to correctly handle the `EOF` error, and adds a 50ms sleep before re-trying a `EAGAIN` error that is achieved thanks to a neat trick suggested by the [`sleep` npm package][sleep]: using `Atomics.wait` enables syncrhonous sleep to be done in `node` without having to ship a native module. [sleep]: https://www.npmjs.com/package/sleep
- Loading branch information
1 parent
66e2ac8
commit 1453ed3
Showing
5 changed files
with
98 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// We need a shared buffer array for the purpose of this exercise. | ||
const array = new Int32Array(new SharedArrayBuffer(4)); | ||
|
||
/** | ||
* Sleeps for a set amount of time, synchronously. | ||
* | ||
* @param time the amount of time to wait, in milliseconds. | ||
*/ | ||
export function sleep(time: number): void { | ||
// `Atomics.wait` will block for `time` milliseconds if `array[0]` still has | ||
// value `0` (which it will, since we just initialized it to that). The return | ||
// value is irrelevant for our business here. | ||
Atomics.wait(array, 0, 0, time); | ||
} |
This file contains 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
This file contains 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