| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fad188f commit 184e80a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,7 @@ function eos(stream, opts, callback) { | |||
| 72 | 72 | // TODO (ronag): Improve soft detection to include core modules and | |
| 73 | 73 | // common ecosystem modules that do properly emit 'close' but fail | |
| 74 | 74 | // this generic check. | |
| 75 | - const willEmitClose = ( | ||
| 75 | + let willEmitClose = ( | ||
| 76 | 76 | state && | |
| 77 | 77 | state.autoDestroy && | |
| 78 | 78 | state.emitClose && | |
@@ -85,6 +85,11 @@ function eos(stream, opts, callback) { | |||
| 85 | 85 | (wState && wState.finished); | |
| 86 | 86 | const onfinish = () => { | |
| 87 | 87 | writableFinished = true; | |
| 88 | + // Stream should not be destroyed here. If it is that | ||
| 89 | + // means that user space is doing something differently and | ||
| 90 | + // we cannot trust willEmitClose. | ||
| 91 | + if (stream.destroyed) willEmitClose = false; | ||
| 92 | + | ||
| 88 | 93 | if (willEmitClose && (!stream.readable || readable)) return; | |
| 89 | 94 | if (!readable || readableEnded) callback.call(stream); | |
| 90 | 95 | }; | |
@@ -93,6 +98,11 @@ function eos(stream, opts, callback) { | |||
| 93 | 98 | (rState && rState.endEmitted); | |
| 94 | 99 | const onend = () => { | |
| 95 | 100 | readableEnded = true; | |
| 101 | + // Stream should not be destroyed here. If it is that | ||
| 102 | + // means that user space is doing something differently and | ||
| 103 | + // we cannot trust willEmitClose. | ||
| 104 | + if (stream.destroyed) willEmitClose = false; | ||
| 105 | + | ||
| 96 | 106 | if (willEmitClose && (!stream.writable || writable)) return; | |
| 97 | 107 | if (!writable || writableFinished) callback.call(stream); | |
| 98 | 108 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -384,3 +384,15 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); | |||
| 384 | 384 | ||
| 385 | 385 | d.resume(); | |
| 386 | 386 | } | |
| 387 | + | ||
| 388 | + { | ||
| 389 | + // Test for compat for e.g. fd-slicer which implements | ||
| 390 | + // non standard destroy behavior which might not emit | ||
| 391 | + // 'close'. | ||
| 392 | + const r = new Readable(); | ||
| 393 | + finished(r, common.mustCall()); | ||
| 394 | + r.resume(); | ||
| 395 | + r.push('asd'); | ||
| 396 | + r.destroyed = true; | ||
| 397 | + r.push(null); | ||
| 398 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments