@@ -130,24 +130,42 @@ export function ConcurrencyQueue ({ axios, config }) {
130
130
131
131
return new Promise ( ( resolve , reject ) => {
132
132
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
140
135
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
141
140
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
+ } )
143
149
. catch ( ( retryError ) => {
144
150
// Check if this is still a transient error and we can retry again
145
151
const retryErrorInfo = isTransientNetworkError ( retryError )
146
152
if ( retryErrorInfo ) {
147
153
retryNetworkError ( retryError , retryErrorInfo , attempt + 1 )
148
154
. 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
+ } )
150
163
} 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
151
169
reject ( retryError )
152
170
}
153
171
} )
0 commit comments