GeezerVison is showing github.com — process: allow reading from stdout/stderr sockets · nodejs/node@5a30674
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/errors.md +31-12Lines changed: 31 additions & 12 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1555,18 +1555,6 @@ An attempt was made to operate on an already closed socket. | 1555 | 1555 |
| 1556 | 1556 | A call was made and the UDP subsystem was not running. | 1557 | 1557 |
| 1558 | | -<a id="ERR_STDERR_CLOSE"></a> | 1559 | | -### ERR_STDERR_CLOSE | 1560 | | - | 1561 | | -An attempt was made to close the `process.stderr` stream. By design, Node.js | 1562 | | -does not allow `stdout` or `stderr` streams to be closed by user code. | 1563 | | - | 1564 | | -<a id="ERR_STDOUT_CLOSE"></a> | 1565 | | -### ERR_STDOUT_CLOSE | 1566 | | - | 1567 | | -An attempt was made to close the `process.stdout` stream. By design, Node.js | 1568 | | -does not allow `stdout` or `stderr` streams to be closed by user code. | 1569 | | - | 1570 | 1558 | <a id="ERR_STREAM_CANNOT_PIPE"></a> | 1571 | 1559 | ### ERR_STREAM_CANNOT_PIPE | 1572 | 1560 |
| @@ -1952,6 +1940,37 @@ removed: v10.0.0 | 1952 | 1940 |
| 1953 | 1941 | The `repl` module was unable to parse data from the REPL history file. | 1954 | 1942 |
| | 1943 | + | | 1944 | +<a id="ERR_STDERR_CLOSE"></a> | | 1945 | +### ERR_STDERR_CLOSE | | 1946 | +<!-- YAML | | 1947 | +removed: REPLACEME | | 1948 | +changes: | | 1949 | + - version: REPLACEME | | 1950 | + pr-url: https://github.com/nodejs/node/pull/23053 | | 1951 | + description: Rather than emitting an error, `process.stderr.end()` now | | 1952 | + only closes the stream side but not the underlying resource, | | 1953 | + making this error obsolete. | | 1954 | +--> | | 1955 | + | | 1956 | +An attempt was made to close the `process.stderr` stream. By design, Node.js | | 1957 | +does not allow `stdout` or `stderr` streams to be closed by user code. | | 1958 | + | | 1959 | +<a id="ERR_STDOUT_CLOSE"></a> | | 1960 | +### ERR_STDOUT_CLOSE | | 1961 | +<!-- YAML | | 1962 | +removed: REPLACEME | | 1963 | +changes: | | 1964 | + - version: REPLACEME | | 1965 | + pr-url: https://github.com/nodejs/node/pull/23053 | | 1966 | + description: Rather than emitting an error, `process.stderr.end()` now | | 1967 | + only closes the stream side but not the underlying resource, | | 1968 | + making this error obsolete. | | 1969 | +--> | | 1970 | + | | 1971 | +An attempt was made to close the `process.stdout` stream. By design, Node.js | | 1972 | +does not allow `stdout` or `stderr` streams to be closed by user code. | | 1973 | + | 1955 | 1974 | <a id="ERR_STREAM_READ_NOT_IMPLEMENTED"></a> | 1956 | 1975 | ### ERR_STREAM_READ_NOT_IMPLEMENTED | 1957 | 1976 | <!-- YAML | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/process.md +1-5Lines changed: 1 addition & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1907,9 +1907,7 @@ important ways: | 1907 | 1907 |
| 1908 | 1908 | 1. They are used internally by [`console.log()`][] and [`console.error()`][], | 1909 | 1909 | respectively. | 1910 | | -2. They cannot be closed ([`end()`][] will throw). | 1911 | | -3. They will never emit the [`'finish'`][] event. | 1912 | | -4. Writes may be synchronous depending on what the stream is connected to | | 1910 | +2. Writes may be synchronous depending on what the stream is connected to | 1913 | 1911 | and whether the system is Windows or POSIX: | 1914 | 1912 | - Files: *synchronous* on Windows and POSIX | 1915 | 1913 | - TTYs (Terminals): *asynchronous* on Windows, *synchronous* on POSIX | @@ -2134,7 +2132,6 @@ cases: | 2134 | 2132 | code will be `128` + `6`, or `134`. | 2135 | 2133 |
| 2136 | 2134 | [`'exit'`]: #process_event_exit | 2137 | | -[`'finish'`]: stream.html#stream_event_finish | 2138 | 2135 | [`'message'`]: child_process.html#child_process_event_message | 2139 | 2136 | [`'rejectionHandled'`]: #process_event_rejectionhandled | 2140 | 2137 | [`'uncaughtException'`]: #process_event_uncaughtexception | @@ -2148,7 +2145,6 @@ cases: | 2148 | 2145 | [`console.error()`]: console.html#console_console_error_data_args | 2149 | 2146 | [`console.log()`]: console.html#console_console_log_data_args | 2150 | 2147 | [`domain`]: domain.html | 2151 | | -[`end()`]: stream.html#stream_writable_end_chunk_encoding_callback | 2152 | 2148 | [`net.Server`]: net.html#net_class_net_server | 2153 | 2149 | [`net.Socket`]: net.html#net_class_net_socket | 2154 | 2150 | [`NODE_OPTIONS`]: cli.html#cli_node_options_options | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/errors.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -817,8 +817,6 @@ E('ERR_SOCKET_BUFFER_SIZE', | 817 | 817 | E('ERR_SOCKET_CANNOT_SEND', 'Unable to send data', Error); | 818 | 818 | E('ERR_SOCKET_CLOSED', 'Socket is closed', Error); | 819 | 819 | E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running', Error); | 820 | | -E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed', Error); | 821 | | -E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed', Error); | 822 | 820 | E('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable', Error); | 823 | 821 | E('ERR_STREAM_DESTROYED', 'Cannot call %s after a stream was destroyed', Error); | 824 | 822 | E('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/process/stdio.js +6-12Lines changed: 6 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | const { | 4 | | - ERR_STDERR_CLOSE, | 5 | | - ERR_STDOUT_CLOSE, | 6 | 4 | ERR_UNKNOWN_STDIN_TYPE, | 7 | 5 | ERR_UNKNOWN_STREAM_TYPE | 8 | 6 | } = require('internal/errors').codes; | 9 | 7 |
| 10 | 8 | exports.setupProcessStdio = setupProcessStdio; | 11 | 9 | exports.getMainThreadStdio = getMainThreadStdio; | 12 | 10 |
| | 11 | +function dummyDestroy(err, cb) { cb(err); } | | 12 | + | 13 | 13 | function getMainThreadStdio() { | 14 | 14 | var stdin; | 15 | 15 | var stdout; | @@ -19,11 +19,8 @@ function getMainThreadStdio() { | 19 | 19 | if (stdout) return stdout; | 20 | 20 | stdout = createWritableStdioStream(1); | 21 | 21 | stdout.destroySoon = stdout.destroy; | 22 | | - stdout._destroy = function(er, cb) { | 23 | | - // Avoid errors if we already emitted | 24 | | - er = er || new ERR_STDOUT_CLOSE(); | 25 | | - cb(er); | 26 | | - }; | | 22 | + // Override _destroy so that the fd is never actually closed. | | 23 | + stdout._destroy = dummyDestroy; | 27 | 24 | if (stdout.isTTY) { | 28 | 25 | process.on('SIGWINCH', () => stdout._refreshSize()); | 29 | 26 | } | @@ -34,11 +31,8 @@ function getMainThreadStdio() { | 34 | 31 | if (stderr) return stderr; | 35 | 32 | stderr = createWritableStdioStream(2); | 36 | 33 | stderr.destroySoon = stderr.destroy; | 37 | | - stderr._destroy = function(er, cb) { | 38 | | - // Avoid errors if we already emitted | 39 | | - er = er || new ERR_STDERR_CLOSE(); | 40 | | - cb(er); | 41 | | - }; | | 34 | + // Override _destroy so that the fd is never actually closed. | | 35 | + stdout._destroy = dummyDestroy; | 42 | 36 | if (stderr.isTTY) { | 43 | 37 | process.on('SIGWINCH', () => stderr._refreshSize()); | 44 | 38 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,9 +24,9 @@ function parent() { | 24 | 24 | }); | 25 | 25 |
| 26 | 26 | child.on('close', function(code, signal) { | 27 | | - assert(code); | | 27 | + assert.strictEqual(code, 0); | | 28 | + assert.strictEqual(err, ''); | 28 | 29 | assert.strictEqual(out, 'foo'); | 29 | | - assert(/process\.stdout cannot be closed/.test(err)); | 30 | 30 | console.log('ok'); | 31 | 31 | }); | 32 | 32 | } |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Hello! |
Collapse file Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../common'); | | 3 | +process.stderr.on('data', common.mustCall(console.log)); |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +<Buffer 48 65 6c 6c 6f 21 0a> |
|