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 5085813

Browse filesBrowse files
RafaelGSSruyadorno
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 bd5d158 commit 5085813
Copy full SHA for 5085813

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
@@ -2463,6 +2463,28 @@ run().catch(console.error);
24632463
after the `callback` has been invoked. In the case of reuse of streams after
24642464
failure, this can cause event listener leaks and swallowed errors.
24652465

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+
24662488
### `stream.compose(...streams)`
24672489

24682490
<!-- YAML

0 commit comments

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