@@ -317,6 +317,40 @@ export async function uploadArtifact(options: OptionsType<{ message: string; app
317317 return uploadResponse . data ;
318318}
319319
320+ async function putUploadWithRetry ( url : string , file : fs . ReadStream , headers : any , maxRetries = 5 ) {
321+ let attempt = 0 ;
322+ let delay = 1000 ;
323+
324+ while ( true ) {
325+ try {
326+ return await axios . put ( url , file , {
327+ maxContentLength : Infinity ,
328+ maxBodyLength : Infinity ,
329+ headers,
330+ transformRequest : [ ( d ) => d ] ,
331+ responseType : 'arraybuffer' ,
332+ } ) ;
333+ } catch ( error : any ) {
334+ const status = error ?. response ?. status ;
335+ const retryable =
336+ status === 503 ||
337+ error ?. code === 'ECONNRESET' ||
338+ error ?. message ?. includes ( 'socket hang up' ) ;
339+
340+ if ( ! retryable || attempt >= maxRetries ) {
341+ throw error ;
342+ }
343+ attempt ++ ;
344+ const jitter = Math . floor ( Math . random ( ) * 300 ) ;
345+
346+ await new Promise ( ( resolve ) => setTimeout ( resolve , delay + jitter ) ) ; // SLEEP
347+
348+ delay *= 2 ;
349+ }
350+ }
351+
352+ }
353+
320354export async function uploadArtifactWithSignedUrl (
321355 options : OptionsType < { app : string ; uploadInfo : FileUploadInformation } >
322356) {
@@ -338,15 +372,9 @@ export async function uploadArtifactWithSignedUrl(
338372
339373 if ( ! configuration || ! configuration . httpMethod || configuration . httpMethod === 'PUT' ) {
340374 const file = fs . createReadStream ( app ) ;
341- return axios . put ( uploadUrl , file , {
342- maxContentLength : Infinity ,
343- maxBodyLength : Infinity ,
344- headers : {
375+ return putUploadWithRetry ( uploadUrl , file , {
345376 'Content-Length' : stats . size ,
346- 'Content-Type' : 'application/octet-stream' ,
347- } ,
348- transformRequest : [ ( d ) => d ] ,
349- responseType : 'arraybuffer' ,
377+ 'Content-Type' : 'application/octet-stream' ,
350378 } ) ;
351379 }
352380
0 commit comments