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 @@ -2463,6 +2463,28 @@ run().catch(console.error);
24632463after the ` callback ` has been invoked. In the case of reuse of streams after
24642464failure, this can cause event listener leaks and swallowed errors.
24652465
2466+ ` stream.pipeline() ` closes all the streams when an error is raised.
2467+ The ` IncomingRequest ` usage with ` pipeline ` could lead to an unexpected behavior
2468+ once it would destroy the socket without sending the expected response.
2469+ See the example below:
2470+
2471+ ``` js
2472+ const fs = require (' fs' );
2473+ const http = require (' http' );
2474+ const { pipeline } = require (' stream' );
2475+
2476+ const server = http .createServer ((req , res ) => {
2477+ const fileStream = fs .createReadStream (' ./fileNotExist.txt' );
2478+ pipeline (fileStream, res, (err ) => {
2479+ if (err) {
2480+ console .log (err); // No such file
2481+ // this message can't be sent once `pipeline` already destroyed the socket
2482+ return res .end (' error!!!' );
2483+ }
2484+ });
2485+ });
2486+ ```
2487+
24662488### ` stream.compose(...streams) `
24672489
24682490<!-- YAML
You can’t perform that action at this time.
0 commit comments