| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bbf7b92 commit ffae5f3
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,8 +145,11 @@ function ReadableState(options, stream, isDuplex) { | |||
| 145 | 145 | // Has it been destroyed. | |
| 146 | 146 | this.destroyed = false; | |
| 147 | 147 | ||
| 148 | - // Indicates whether the stream has errored. | ||
| 149 | - this.errored = false; | ||
| 148 | + // Indicates whether the stream has errored. When true no further | ||
| 149 | + // _read calls, 'data' or 'readable' events should occur. This is needed | ||
| 150 | + // since when autoDestroy is disabled we need a way to tell whether the | ||
| 151 | + // stream has failed. | ||
| 152 | + this.errored = null; | ||
| 150 | 153 | ||
| 151 | 154 | // Indicates whether the stream has finished destroying. | |
| 152 | 155 | this.closed = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,7 +171,7 @@ function WritableState(options, stream, isDuplex) { | |||
| 171 | 171 | // Indicates whether the stream has errored. When true all write() calls | |
| 172 | 172 | // should return false. This is needed since when autoDestroy | |
| 173 | 173 | // is disabled we need a way to tell whether the stream has failed. | |
| 174 | - this.errored = false; | ||
| 174 | + this.errored = null; | ||
| 175 | 175 | ||
| 176 | 176 | // Indicates whether the stream has finished destroying. | |
| 177 | 177 | this.closed = false; | |
@@ -407,7 +407,19 @@ function onwrite(stream, er) { | |||
| 407 | 407 | state.writelen = 0; | |
| 408 | 408 | ||
| 409 | 409 | if (er) { | |
| 410 | - state.errored = true; | ||
| 410 | + // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 | ||
| 411 | + er.stack; | ||
| 412 | + | ||
| 413 | + if (!state.errored) { | ||
| 414 | + state.errored = er; | ||
| 415 | + } | ||
| 416 | + | ||
| 417 | + // In case of duplex streams we need to notify the readable side of the | ||
| 418 | + // error. | ||
| 419 | + if (stream._readableState && !stream._readableState.errored) { | ||
| 420 | + stream._readableState.errored = er; | ||
| 421 | + } | ||
| 422 | + | ||
| 411 | 423 | if (sync) { | |
| 412 | 424 | process.nextTick(onwriteError, stream, state, er, cb); | |
| 413 | 425 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,11 +15,14 @@ function destroy(err, cb) { | |||
| 15 | 15 | } | |
| 16 | 16 | ||
| 17 | 17 | if (err) { | |
| 18 | - if (w) { | ||
| 19 | - w.errored = true; | ||
| 18 | + // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 | ||
| 19 | + err.stack; | ||
| 20 | + | ||
| 21 | + if (w && !w.errored) { | ||
| 22 | + w.errored = err; | ||
| 20 | 23 | } | |
| 21 | - if (r) { | ||
| 22 | - r.errored = true; | ||
| 24 | + if (r && !r.errored) { | ||
| 25 | + r.errored = err; | ||
| 23 | 26 | } | |
| 24 | 27 | } | |
| 25 | 28 | ||
@@ -35,11 +38,14 @@ function destroy(err, cb) { | |||
| 35 | 38 | ||
| 36 | 39 | this._destroy(err || null, (err) => { | |
| 37 | 40 | if (err) { | |
| 38 | - if (w) { | ||
| 39 | - w.errored = true; | ||
| 41 | + // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 | ||
| 42 | + err.stack; | ||
| 43 | + | ||
| 44 | + if (w && !w.errored) { | ||
| 45 | + w.errored = err; | ||
| 40 | 46 | } | |
| 41 | - if (r) { | ||
| 42 | - r.errored = true; | ||
| 47 | + if (r && !r.errored) { | ||
| 48 | + r.errored = err; | ||
| 43 | 49 | } | |
| 44 | 50 | } | |
| 45 | 51 | ||
@@ -108,7 +114,7 @@ function undestroy() { | |||
| 108 | 114 | r.closed = false; | |
| 109 | 115 | r.closeEmitted = false; | |
| 110 | 116 | r.destroyed = false; | |
| 111 | - r.errored = false; | ||
| 117 | + r.errored = null; | ||
| 112 | 118 | r.errorEmitted = false; | |
| 113 | 119 | r.reading = false; | |
| 114 | 120 | r.ended = false; | |
@@ -118,7 +124,7 @@ function undestroy() { | |||
| 118 | 124 | if (w) { | |
| 119 | 125 | w.closed = false; | |
| 120 | 126 | w.destroyed = false; | |
| 121 | - w.errored = false; | ||
| 127 | + w.errored = null; | ||
| 122 | 128 | w.ended = false; | |
| 123 | 129 | w.ending = false; | |
| 124 | 130 | w.finalCalled = false; | |
@@ -145,11 +151,14 @@ function errorOrDestroy(stream, err, sync) { | |||
| 145 | 151 | if ((r && r.autoDestroy) || (w && w.autoDestroy)) | |
| 146 | 152 | stream.destroy(err); | |
| 147 | 153 | else if (err) { | |
| 148 | - if (w) { | ||
| 149 | - w.errored = true; | ||
| 154 | + // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 | ||
| 155 | + err.stack; | ||
| 156 | + | ||
| 157 | + if (w && !w.errored) { | ||
| 158 | + w.errored = err; | ||
| 150 | 159 | } | |
| 151 | - if (r) { | ||
| 152 | - r.errored = true; | ||
| 160 | + if (r && !r.errored) { | ||
| 161 | + r.errored = err; | ||
| 153 | 162 | } | |
| 154 | 163 | ||
| 155 | 164 | if (sync) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -134,13 +134,13 @@ const assert = require('assert'); | |||
| 134 | 134 | read.on('error', common.mustCall((err) => { | |
| 135 | 135 | assert.strictEqual(ticked, true); | |
| 136 | 136 | assert.strictEqual(read._readableState.errorEmitted, true); | |
| 137 | - assert.strictEqual(read._readableState.errored, true); | ||
| 137 | + assert.strictEqual(read._readableState.errored, expected); | ||
| 138 | 138 | assert.strictEqual(err, expected); | |
| 139 | 139 | })); | |
| 140 | 140 | ||
| 141 | 141 | read.destroy(); | |
| 142 | 142 | assert.strictEqual(read._readableState.errorEmitted, false); | |
| 143 | - assert.strictEqual(read._readableState.errored, true); | ||
| 143 | + assert.strictEqual(read._readableState.errored, expected); | ||
| 144 | 144 | assert.strictEqual(read.destroyed, true); | |
| 145 | 145 | ticked = true; | |
| 146 | 146 | } | |
@@ -190,15 +190,15 @@ const assert = require('assert'); | |||
| 190 | 190 | assert.strictEqual(err, expected); | |
| 191 | 191 | })); | |
| 192 | 192 | ||
| 193 | - assert.strictEqual(read._readableState.errored, false); | ||
| 193 | + assert.strictEqual(read._readableState.errored, null); | ||
| 194 | 194 | assert.strictEqual(read._readableState.errorEmitted, false); | |
| 195 | 195 | ||
| 196 | 196 | read.destroy(expected, common.mustCall(function(err) { | |
| 197 | - assert.strictEqual(read._readableState.errored, true); | ||
| 197 | + assert.strictEqual(read._readableState.errored, expected); | ||
| 198 | 198 | assert.strictEqual(err, expected); | |
| 199 | 199 | })); | |
| 200 | 200 | assert.strictEqual(read._readableState.errorEmitted, false); | |
| 201 | - assert.strictEqual(read._readableState.errored, true); | ||
| 201 | + assert.strictEqual(read._readableState.errored, expected); | ||
| 202 | 202 | ticked = true; | |
| 203 | 203 | } | |
| 204 | 204 | ||
@@ -223,14 +223,14 @@ const assert = require('assert'); | |||
| 223 | 223 | ||
| 224 | 224 | readable.destroy(); | |
| 225 | 225 | assert.strictEqual(readable.destroyed, true); | |
| 226 | - assert.strictEqual(readable._readableState.errored, false); | ||
| 226 | + assert.strictEqual(readable._readableState.errored, null); | ||
| 227 | 227 | assert.strictEqual(readable._readableState.errorEmitted, false); | |
| 228 | 228 | ||
| 229 | 229 | // Test case where `readable.destroy()` is called again with an error before | |
| 230 | 230 | // the `_destroy()` callback is called. | |
| 231 | 231 | readable.destroy(new Error('kaboom 2')); | |
| 232 | 232 | assert.strictEqual(readable._readableState.errorEmitted, false); | |
| 233 | - assert.strictEqual(readable._readableState.errored, false); | ||
| 233 | + assert.strictEqual(readable._readableState.errored, null); | ||
| 234 | 234 | ||
| 235 | 235 | ticked = true; | |
| 236 | 236 | } | |
@@ -253,3 +253,18 @@ const assert = require('assert'); | |||
| 253 | 253 | assert.strictEqual(read.destroyed, true); | |
| 254 | 254 | read.read(); | |
| 255 | 255 | } | |
| 256 | + | ||
| 257 | + { | ||
| 258 | + const read = new Readable({ | ||
| 259 | + autoDestroy: false, | ||
| 260 | + read() { | ||
| 261 | + this.push(null); | ||
| 262 | + this.push('asd'); | ||
| 263 | + } | ||
| 264 | + }); | ||
| 265 | + | ||
| 266 | + read.on('error', common.mustCall(() => { | ||
| 267 | + assert(read._readableState.errored); | ||
| 268 | + })); | ||
| 269 | + read.resume(); | ||
| 270 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,9 +167,10 @@ const assert = require('assert'); | |||
| 167 | 167 | assert.strictEqual(write._writableState.errorEmitted, true); | |
| 168 | 168 | })); | |
| 169 | 169 | ||
| 170 | - write.destroy(new Error('kaboom 1')); | ||
| 170 | + const expected = new Error('kaboom 1'); | ||
| 171 | + write.destroy(expected); | ||
| 171 | 172 | write.destroy(new Error('kaboom 2')); | |
| 172 | - assert.strictEqual(write._writableState.errored, true); | ||
| 173 | + assert.strictEqual(write._writableState.errored, expected); | ||
| 173 | 174 | assert.strictEqual(write._writableState.errorEmitted, false); | |
| 174 | 175 | assert.strictEqual(write.destroyed, true); | |
| 175 | 176 | ticked = true; | |
@@ -200,14 +201,14 @@ const assert = require('assert'); | |||
| 200 | 201 | ||
| 201 | 202 | writable.destroy(); | |
| 202 | 203 | assert.strictEqual(writable.destroyed, true); | |
| 203 | - assert.strictEqual(writable._writableState.errored, false); | ||
| 204 | + assert.strictEqual(writable._writableState.errored, null); | ||
| 204 | 205 | assert.strictEqual(writable._writableState.errorEmitted, false); | |
| 205 | 206 | ||
| 206 | 207 | // Test case where `writable.destroy()` is called again with an error before | |
| 207 | 208 | // the `_destroy()` callback is called. | |
| 208 | 209 | writable.destroy(new Error('kaboom 2')); | |
| 209 | 210 | assert.strictEqual(writable._writableState.errorEmitted, false); | |
| 210 | - assert.strictEqual(writable._writableState.errored, false); | ||
| 211 | + assert.strictEqual(writable._writableState.errored, null); | ||
| 211 | 212 | ||
| 212 | 213 | ticked = true; | |
| 213 | 214 | } | |
@@ -401,3 +402,18 @@ const assert = require('assert'); | |||
| 401 | 402 | })); | |
| 402 | 403 | write.destroy(); | |
| 403 | 404 | } | |
| 405 | + | ||
| 406 | + { | ||
| 407 | + const write = new Writable({ | ||
| 408 | + autoDestroy: false, | ||
| 409 | + write(chunk, enc, cb) { | ||
| 410 | + cb(); | ||
| 411 | + cb(); | ||
| 412 | + } | ||
| 413 | + }); | ||
| 414 | + | ||
| 415 | + write.on('error', common.mustCall(() => { | ||
| 416 | + assert(write._writableState.errored); | ||
| 417 | + })); | ||
| 418 | + write.write('asd'); | ||
| 419 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,23 +10,25 @@ oldStream.pause = () => {}; | |||
| 10 | 10 | oldStream.resume = () => {}; | |
| 11 | 11 | ||
| 12 | 12 | { | |
| 13 | + const err = new Error(); | ||
| 13 | 14 | const r = new Readable({ autoDestroy: true }) | |
| 14 | 15 | .wrap(oldStream) | |
| 15 | 16 | .on('error', common.mustCall(() => { | |
| 16 | 17 | assert.strictEqual(r._readableState.errorEmitted, true); | |
| 17 | - assert.strictEqual(r._readableState.errored, true); | ||
| 18 | + assert.strictEqual(r._readableState.errored, err); | ||
| 18 | 19 | assert.strictEqual(r.destroyed, true); | |
| 19 | 20 | })); | |
| 20 | - oldStream.emit('error', new Error()); | ||
| 21 | + oldStream.emit('error', err); | ||
| 21 | 22 | } | |
| 22 | 23 | ||
| 23 | 24 | { | |
| 25 | + const err = new Error(); | ||
| 24 | 26 | const r = new Readable({ autoDestroy: false }) | |
| 25 | 27 | .wrap(oldStream) | |
| 26 | 28 | .on('error', common.mustCall(() => { | |
| 27 | 29 | assert.strictEqual(r._readableState.errorEmitted, true); | |
| 28 | - assert.strictEqual(r._readableState.errored, true); | ||
| 30 | + assert.strictEqual(r._readableState.errored, err); | ||
| 29 | 31 | assert.strictEqual(r.destroyed, false); | |
| 30 | 32 | })); | |
| 31 | - oldStream.emit('error', new Error()); | ||
| 33 | + oldStream.emit('error', err); | ||
| 32 | 34 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments