@@ -130,24 +130,42 @@ export function ConcurrencyQueue ({ axios, config }) {
130130
131131 return new Promise ( ( resolve , reject ) => {
132132 setTimeout ( ( ) => {
133- // Remove the failed request from running queue
134- const runningIndex = this . running . findIndex ( item => item . request === error . config )
135- if ( runningIndex !== - 1 ) {
136- this . running . splice ( runningIndex , 1 )
137- }
138-
139- // Retry the request
133+ // Keep the request in running queue to maintain maxRequests constraint
134+ // Set retry flags to ensure proper queue handling
140135 const sanitizedConfig = validateAndSanitizeConfig ( updateRequestConfig ( error , `Network retry ${ attempt } ` , delay ) )
136+ sanitizedConfig . retryCount = sanitizedConfig . retryCount || 0
137+
138+ // Use axios directly but ensure the running queue is properly managed
139+ // The request interceptor will handle this retry appropriately
141140 axios ( sanitizedConfig )
142- . then ( resolve )
141+ . then ( ( response ) => {
142+ // On successful retry, call the original onComplete to properly clean up
143+ if ( error . config . onComplete ) {
144+ error . config . onComplete ( )
145+ }
146+ shift ( ) // Process next queued request
147+ resolve ( response )
148+ } )
143149 . catch ( ( retryError ) => {
144150 // Check if this is still a transient error and we can retry again
145151 const retryErrorInfo = isTransientNetworkError ( retryError )
146152 if ( retryErrorInfo ) {
147153 retryNetworkError ( retryError , retryErrorInfo , attempt + 1 )
148154 . then ( resolve )
149- . catch ( reject )
155+ . catch ( ( finalError ) => {
156+ // On final failure, clean up the running queue
157+ if ( error . config . onComplete ) {
158+ error . config . onComplete ( )
159+ }
160+ shift ( ) // Process next queued request
161+ reject ( finalError )
162+ } )
150163 } else {
164+ // On non-retryable error, clean up the running queue
165+ if ( error . config . onComplete ) {
166+ error . config . onComplete ( )
167+ }
168+ shift ( ) // Process next queued request
151169 reject ( retryError )
152170 }
153171 } )
0 commit comments