Skip to content

Commit 7f235dc

Browse files
committed
doc: add steam pipelining note on Http usage
1 parent 4fbe9e5 commit 7f235dc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/api/stream.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,28 @@ run().catch(console.error);
25172517
after the `callback` has been invoked. In the case of reuse of streams after
25182518
failure, 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

0 commit comments

Comments
 (0)