Skip to content

Commit 3ac9e80

Browse files
RafaelGSSdanielleadams
authored andcommitted
doc: add stream pipelining note on Http usage
PR-URL: nodejs#41796 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Mary Marchini <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8ca4c05 commit 3ac9e80

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/api/stream.md

+22
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,28 @@ run().catch(console.error);
21662166
after the `callback` has been invoked. In the case of reuse of streams after
21672167
failure, this can cause event listener leaks and swallowed errors.
21682168

2169+
`stream.pipeline()` closes all the streams when an error is raised.
2170+
The `IncomingRequest` usage with `pipeline` could lead to an unexpected behavior
2171+
once it would destroy the socket without sending the expected response.
2172+
See the example below:
2173+
2174+
```js
2175+
const fs = require('fs');
2176+
const http = require('http');
2177+
const { pipeline } = require('stream');
2178+
2179+
const server = http.createServer((req, res) => {
2180+
const fileStream = fs.createReadStream('./fileNotExist.txt');
2181+
pipeline(fileStream, res, (err) => {
2182+
if (err) {
2183+
console.log(err); // No such file
2184+
// this message can't be sent once `pipeline` already destroyed the socket
2185+
return res.end('error!!!');
2186+
}
2187+
});
2188+
});
2189+
```
2190+
21692191
### `stream.compose(...streams)`
21702192

21712193
<!-- YAML

0 commit comments

Comments
 (0)