File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -1845,6 +1845,7 @@ async function httpNetworkFetch (
1845
1845
// 4. Set bytes to the result of handling content codings given
1846
1846
// codings and bytes.
1847
1847
let bytes
1848
+ let isFailure
1848
1849
try {
1849
1850
const { done, value } = await fetchParams . controller . next ( )
1850
1851
@@ -1859,6 +1860,10 @@ async function httpNetworkFetch (
1859
1860
bytes = undefined
1860
1861
} else {
1861
1862
bytes = err
1863
+
1864
+ // err may be propagated from the result of calling readablestream.cancel,
1865
+ // which might not be an error. https://github.com/nodejs/undici/issues/2009
1866
+ isFailure = true
1862
1867
}
1863
1868
}
1864
1869
@@ -1878,7 +1883,7 @@ async function httpNetworkFetch (
1878
1883
timingInfo . decodedBodySize += bytes ?. byteLength ?? 0
1879
1884
1880
1885
// 6. If bytes is failure, then terminate fetchParams’s controller.
1881
- if ( isErrorLike ( bytes ) ) {
1886
+ if ( isFailure ) {
1882
1887
fetchParams . controller . terminate ( bytes )
1883
1888
return
1884
1889
}
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const { test } = require ( 'tap' )
4
+ const { fetch } = require ( '../..' )
5
+ const { createServer } = require ( 'http' )
6
+ const { once } = require ( 'events' )
7
+
8
+ test ( 'issue 2009' , async ( t ) => {
9
+ const server = createServer ( ( req , res ) => {
10
+ res . setHeader ( 'a' , 'b' )
11
+ res . flushHeaders ( )
12
+
13
+ res . socket . end ( )
14
+ } ) . listen ( 0 )
15
+
16
+ t . teardown ( server . close . bind ( server ) )
17
+ await once ( server , 'listening' )
18
+
19
+ for ( let i = 0 ; i < 10 ; i ++ ) {
20
+ await t . resolves (
21
+ fetch ( `http://localhost:${ server . address ( ) . port } ` ) . then (
22
+ async ( resp ) => {
23
+ await resp . body . cancel ( 'Some message' )
24
+ }
25
+ )
26
+ )
27
+ }
28
+ } )
You can’t perform that action at this time.
0 commit comments