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 @@ -2517,6 +2517,28 @@ run().catch(console.error);
25172517after the ` callback ` has been invoked. In the case of reuse of streams after
25182518failure, this can cause event listener leaks and swallowed errors.
25192519
2520+ ` stream.pipeline() ` closes all the streams when an error is raised.
2521+ The ` IncomingRequest ` usage with ` pipeline ` could lead to an unexpected behavior
2522+ once it would destroy the socket without sending the expected response.
2523+ See the example below:
2524+
2525+ ``` js
2526+ const fs = require (' fs' );
2527+ const http = require (' http' );
2528+ const { pipeline } = require (' stream' );
2529+
2530+ const server = http .createServer ((req , res ) => {
2531+ const fileStream = fs .createReadStream (' ./fileNotExist.txt' );
2532+ pipeline (fileStream, res, (err ) => {
2533+ if (err) {
2534+ console .log (err); // No such file
2535+ // this message can't be sent once `pipeline` already destroyed the socket
2536+ return res .end (' error!!!' );
2537+ }
2538+ });
2539+ });
2540+ ```
2541+
25202542### ` stream.compose(...streams) `
25212543
25222544<!-- YAML
You can’t perform that action at this time.
0 commit comments