@@ -259,6 +259,18 @@ export class RegistryProxy {
259
259
proxyRes . pipe ( response , { end : true } ) ;
260
260
} ) ;
261
261
262
+ request . on ( "close" , ( ) => {
263
+ logger . debug ( "Client closed the connection" ) ;
264
+ proxyReq . destroy ( ) ;
265
+ cleanupTempFile ( ) ;
266
+ } ) ;
267
+
268
+ request . on ( "abort" , ( ) => {
269
+ logger . debug ( "Client aborted the connection" ) ;
270
+ proxyReq . destroy ( ) ; // Abort the proxied request
271
+ cleanupTempFile ( ) ; // Clean up the temporary file if necessary
272
+ } ) ;
273
+
262
274
if ( tempFilePath ) {
263
275
const readStream = createReadStream ( tempFilePath ) ;
264
276
@@ -427,14 +439,22 @@ function initializeProxy() {
427
439
} ) ;
428
440
}
429
441
430
- async function streamRequestBodyToTempFile ( request : IncomingMessage ) : Promise < string > {
431
- const tempDir = await mkdtemp ( `${ tmpdir ( ) } /` ) ;
432
- const tempFilePath = `${ tempDir } /requestBody.tmp` ;
433
- const writeStream = createWriteStream ( tempFilePath ) ;
442
+ async function streamRequestBodyToTempFile ( request : IncomingMessage ) : Promise < string | undefined > {
443
+ try {
444
+ const tempDir = await mkdtemp ( `${ tmpdir ( ) } /` ) ;
445
+ const tempFilePath = `${ tempDir } /requestBody.tmp` ;
446
+ const writeStream = createWriteStream ( tempFilePath ) ;
434
447
435
- await pipeline ( request , writeStream ) ;
448
+ await pipeline ( request , writeStream ) ;
436
449
437
- return tempFilePath ;
450
+ return tempFilePath ;
451
+ } catch ( error ) {
452
+ logger . error ( "Failed to stream request body to temp file" , {
453
+ error : error instanceof Error ? error . message : error ,
454
+ } ) ;
455
+
456
+ return ;
457
+ }
438
458
}
439
459
440
460
type DockerImageParts = {
0 commit comments