File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -1433,6 +1433,7 @@ class File extends ServiceObject<File, FileMetadata> {
1433
1433
const tailRequest = options . end ! < 0 ;
1434
1434
1435
1435
let validateStream : HashStreamValidator | undefined = undefined ;
1436
+ let request : r . Request | undefined = undefined ;
1436
1437
1437
1438
const throughStream = new PassThroughShim ( ) ;
1438
1439
@@ -1464,6 +1465,11 @@ class File extends ServiceObject<File, FileMetadata> {
1464
1465
1465
1466
const onComplete = ( err : Error | null ) => {
1466
1467
if ( err ) {
1468
+ // There is an issue with node-fetch 2.x that if the stream errors the underlying socket connection is not closed.
1469
+ // This causes a memory leak, so cleanup the sockets manually here by destroying the agent.
1470
+ if ( request ?. agent ) {
1471
+ request . agent . destroy ( ) ;
1472
+ }
1467
1473
throughStream . destroy ( err ) ;
1468
1474
}
1469
1475
} ;
@@ -1492,6 +1498,7 @@ class File extends ServiceObject<File, FileMetadata> {
1492
1498
return ;
1493
1499
}
1494
1500
1501
+ request = ( rawResponseStream as r . Response ) . request ;
1495
1502
const headers = ( rawResponseStream as ResponseBody ) . toJSON ( ) . headers ;
1496
1503
const isCompressed = headers [ 'content-encoding' ] === 'gzip' ;
1497
1504
const hashes : { crc32c ?: string ; md5 ?: string } = { } ;
You can’t perform that action at this time.
0 commit comments