@@ -1401,3 +1401,62 @@ it('should retry on ECONNRESET', {
14011401 expect ( await response . text ( ) ) . toBe ( 'Hello!' ) ;
14021402 expect ( requestCount ) . toBe ( 4 ) ;
14031403} ) ;
1404+
1405+ it ( 'should retry ECONNRESET on compressed response' , async ( { context, server } ) => {
1406+ let requestCount = 0 ;
1407+ server . setRoute ( '/test-gzip' , ( req , res ) => {
1408+ if ( requestCount ++ < 2 ) {
1409+ req . socket . destroy ( ) ;
1410+ return ;
1411+ }
1412+ res . writeHead ( 200 , {
1413+ 'Content-Encoding' : 'gzip' ,
1414+ 'Content-Type' : 'text/plain' ,
1415+ } ) ;
1416+ const gzipStream = zlib . createGzip ( ) ;
1417+ pipeline ( gzipStream , res , err => {
1418+ if ( err )
1419+ console . log ( `Server error: ${ err } ` ) ;
1420+ } ) ;
1421+ gzipStream . write ( 'compressed-retry-ok' ) ;
1422+ gzipStream . end ( ) ;
1423+ } ) ;
1424+ const response = await context . request . get ( server . PREFIX + '/test-gzip' , { maxRetries : 3 } ) ;
1425+ expect ( response . status ( ) ) . toBe ( 200 ) ;
1426+ expect ( await response . text ( ) ) . toBe ( 'compressed-retry-ok' ) ;
1427+ expect ( requestCount ) . toBe ( 3 ) ;
1428+ } ) ;
1429+
1430+ it ( 'should retry ECONNRESET mid-stream during gzip decompression' , async ( { context, server } ) => {
1431+ let requestCount = 0 ;
1432+ server . setRoute ( '/test-gzip-midstream' , ( req , res ) => {
1433+ requestCount ++ ;
1434+ if ( requestCount <= 2 ) {
1435+ // Send response headers to make client enter the decompression pipeline,
1436+ // then destroy the socket. This exercises the fix: without it, the
1437+ // pipeline error callback wraps the error, stripping .code for retry.
1438+ res . writeHead ( 200 , {
1439+ 'Content-Encoding' : 'gzip' ,
1440+ 'Content-Type' : 'text/plain' ,
1441+ } ) ;
1442+ res . flushHeaders ( ) ;
1443+ req . socket . destroy ( ) ;
1444+ return ;
1445+ }
1446+ res . writeHead ( 200 , {
1447+ 'Content-Encoding' : 'gzip' ,
1448+ 'Content-Type' : 'text/plain' ,
1449+ } ) ;
1450+ const gzipStream = zlib . createGzip ( ) ;
1451+ pipeline ( gzipStream , res , err => {
1452+ if ( err )
1453+ console . log ( `Server error: ${ err } ` ) ;
1454+ } ) ;
1455+ gzipStream . write ( 'midstream-retry-ok' ) ;
1456+ gzipStream . end ( ) ;
1457+ } ) ;
1458+ const response = await context . request . get ( server . PREFIX + '/test-gzip-midstream' , { maxRetries : 3 } ) ;
1459+ expect ( response . status ( ) ) . toBe ( 200 ) ;
1460+ expect ( await response . text ( ) ) . toBe ( 'midstream-retry-ok' ) ;
1461+ expect ( requestCount ) . toBe ( 3 ) ;
1462+ } ) ;
0 commit comments