Commit b458ca3
authored
Wait for stdout writing to finish before exiting (#262)
This fixes a race condition when writing to stdout on certain platforms and streams.
As noted in [A note on process I/O](https://nodejs.org/api/process.html#process_a_note_on_process_i_o) in the Node documentation, the `process.stdout` stream is asynchronous in some cases (pipes on POSIX, TTYs on Windows).
In these cases, the output sent to stdout can sometimes be cut off at the first chunk because the linter process exits before the stream is finished writing. The result is either a truncated set of errors (with default output) or invalid JSON (with JSON output) when the set of errors exceeds the default chunk size.
This is fixed by using the return status of `socket.write` to determine if some of the data was queued, then awaiting the socket's `'drain'` event if so before returning.1 parent cf942a2 commit b458ca3
2 files changed
+14
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
| |||
0 commit comments