Commit 39af61f
stream: fix end-of-stream for HTTP/2
HTTP/2 streams call `.end()` on themselves from their
`.destroy()` method, which might be queued (e.g. due to network
congestion) and not processed before the stream itself is destroyed.
In that case, the `_writableState.ended` property could be set before
the stream emits its `'close'` event, and never actually emits the
`'finished'` event, confusing the end-of-stream implementation so
that it wouldn’t call its callback.
This can be fixed by watching for the end events themselves using the
existing `'finish'` and `'end'` listeners rather than relying on the
`.ended` properties of the `_...State` objects.
These properties still need to be checked to know whether stream
closure was premature – My understanding is that ideally, streams
should not emit `'close'` before `'end'` and/or `'finished'`, so this
might be another bug, but changing this would require modifying tests
and almost certainly be a breaking change.
Fixes: #24456
PR-URL: #24926
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>1 parent b2e6cbd commit 39af61fCopy full SHA for 39af61f
File tree
Expand file treeCollapse file tree
3 files changed
+53
-9
lines changedOpen diff view settings
Filter options
- lib/internal/streams
- test/parallel
Expand file treeCollapse file tree
3 files changed
+53
-9
lines changedOpen diff view settings
Collapse file
lib/internal/streams/end-of-stream.js
Copy file name to clipboardExpand all lines: lib/internal/streams/end-of-stream.js+14-7Lines changed: 14 additions & 7 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | | - |
40 | | - |
41 | 39 | |
42 | 40 | |
43 | 41 | |
44 | 42 | |
45 | 43 | |
46 | 44 | |
47 | 45 | |
| 46 | + |
48 | 47 | |
49 | 48 | |
| 49 | + |
50 | 50 | |
51 | 51 | |
52 | 52 | |
| 53 | + |
53 | 54 | |
54 | 55 | |
| 56 | + |
55 | 57 | |
56 | 58 | |
57 | 59 | |
| ||
60 | 62 | |
61 | 63 | |
62 | 64 | |
63 | | - |
64 | | - |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
65 | 70 | |
66 | | - |
67 | | - |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
68 | 75 | |
69 | 76 | |
70 | 77 | |
| ||
77 | 84 | |
78 | 85 | |
79 | 86 | |
80 | | - |
| 87 | + |
81 | 88 | |
82 | 89 | |
83 | 90 | |
|
Collapse file
test/parallel/parallel.status
Copy file name to clipboardExpand all lines: test/parallel/parallel.status-2Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
12 | 12 | |
13 | 13 | |
14 | 14 | |
15 | | - |
16 | | - |
17 | 15 | |
18 | 16 | |
19 | 17 | |
|
Collapse file
test/parallel/test-stream-pipeline-queued-end-in-destroy.js
Copy file name to clipboard+39Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
0 commit comments