| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bd5d158 commit 5085813
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2463,6 +2463,28 @@ run().catch(console.error); | |||
| 2463 | 2463 | after the `callback` has been invoked. In the case of reuse of streams after | |
| 2464 | 2464 | failure, this can cause event listener leaks and swallowed errors. | |
| 2465 | 2465 | ||
| 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 | + | ||
| 2466 | 2488 | ### `stream.compose(...streams)` | |
| 2467 | 2489 | ||
| 2468 | 2490 | <!-- YAML | |
| Back | FazBrowse Home | New Git URL |
0 commit comments