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 88eb619

Browse filesBrowse files
yashLadhatargos
authored andcommitted
stream: fix duplicate logic in stream destroy
Fix duplicate logic in stream destroy as the same logic is being shared across methods and thus can be encapsulated into a single method. PR-URL: #35727 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
1 parent e0a1541 commit 88eb619
Copy full SHA for 88eb619

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

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

‎lib/internal/streams/destroy.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/destroy.js
+16-22Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ const { Symbol } = primordials;
88
const kDestroy = Symbol('kDestroy');
99
const kConstruct = Symbol('kConstruct');
1010

11+
function checkError(err, w, r) {
12+
if (err) {
13+
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
14+
err.stack;
15+
16+
if (w && !w.errored) {
17+
w.errored = err;
18+
}
19+
if (r && !r.errored) {
20+
r.errored = err;
21+
}
22+
}
23+
}
24+
1125
// Backwards compat. cb() is undocumented and unused in core but
1226
// unfortunately might be used by modules.
1327
function destroy(err, cb) {
@@ -24,20 +38,10 @@ function destroy(err, cb) {
2438
return this;
2539
}
2640

27-
if (err) {
28-
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
29-
err.stack;
30-
31-
if (w && !w.errored) {
32-
w.errored = err;
33-
}
34-
if (r && !r.errored) {
35-
r.errored = err;
36-
}
37-
}
3841

3942
// We set destroyed to true before firing error callbacks in order
4043
// to make it re-entrance safe in case destroy() is called within callbacks
44+
checkError(err, w, r);
4145

4246
if (w) {
4347
w.destroyed = true;
@@ -66,17 +70,7 @@ function _destroy(self, err, cb) {
6670

6771
called = true;
6872

69-
if (err) {
70-
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
71-
err.stack;
72-
73-
if (w && !w.errored) {
74-
w.errored = err;
75-
}
76-
if (r && !r.errored) {
77-
r.errored = err;
78-
}
79-
}
73+
checkError(err, w, r);
8074

8175
if (w) {
8276
w.closed = true;

0 commit comments

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