Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 77685d5

Browse filesBrowse files
RafaelGSSdanielleadams
authored andcommitted
doc: add stream pipelining note on Http usage
PR-URL: #41796 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mary Marchini <oss@mmarchini.me> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 70f6554 commit 77685d5
Copy full SHA for 77685d5

File tree

Expand file treeCollapse file tree

1 file changed

+22
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/stream.md‎

Copy file name to clipboardExpand all lines: doc/api/stream.md
+22Lines changed: 22 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,28 @@ run().catch(console.error);
21072107
after the `callback` has been invoked. In the case of reuse of streams after
21082108
failure, this can cause event listener leaks and swallowed errors.
21092109

2110+
`stream.pipeline()` closes all the streams when an error is raised.
2111+
The `IncomingRequest` usage with `pipeline` could lead to an unexpected behavior
2112+
once it would destroy the socket without sending the expected response.
2113+
See the example below:
2114+
2115+
```js
2116+
const fs = require('fs');
2117+
const http = require('http');
2118+
const { pipeline } = require('stream');
2119+
2120+
const server = http.createServer((req, res) => {
2121+
const fileStream = fs.createReadStream('./fileNotExist.txt');
2122+
pipeline(fileStream, res, (err) => {
2123+
if (err) {
2124+
console.log(err); // No such file
2125+
// this message can't be sent once `pipeline` already destroyed the socket
2126+
return res.end('error!!!');
2127+
}
2128+
});
2129+
});
2130+
```
2131+
21102132
### `stream.compose(...streams)`
21112133

21122134
<!-- YAML

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.