Commit 3ac9e80 1 parent 8ca4c05 commit 3ac9e80 Copy full SHA for 3ac9e80
File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2166,6 +2166,28 @@ run().catch(console.error);
2166
2166
after the ` callback ` has been invoked. In the case of reuse of streams after
2167
2167
failure, this can cause event listener leaks and swallowed errors.
2168
2168
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
+
2169
2191
### ` stream.compose(...streams) `
2170
2192
2171
2193
<!-- YAML
You can’t perform that action at this time.
0 commit comments