File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2107,6 +2107,28 @@ run().catch(console.error);
21072107after the ` callback ` has been invoked. In the case of reuse of streams after
21082108failure, this can cause event listener leaks and swallowed errors.
21092109
2110+ ` stream.pipeline() ` closes all the streams when an error is raised.
2111+ The ` IncomingRequest ` usage with ` pipeline ` could lead to an unexpected behavior
2112+ once it would destroy the socket without sending the expected response.
2113+ See the example below:
2114+
2115+ ``` js
2116+ const fs = require (' fs' );
2117+ const http = require (' http' );
2118+ const { pipeline } = require (' stream' );
2119+
2120+ const server = http .createServer ((req , res ) => {
2121+ const fileStream = fs .createReadStream (' ./fileNotExist.txt' );
2122+ pipeline (fileStream, res, (err ) => {
2123+ if (err) {
2124+ console .log (err); // No such file
2125+ // this message can't be sent once `pipeline` already destroyed the socket
2126+ return res .end (' error!!!' );
2127+ }
2128+ });
2129+ });
2130+ ```
2131+
21102132### ` stream.compose(...streams) `
21112133
21122134<!-- YAML
You can’t perform that action at this time.
0 commit comments