@@ -18,6 +18,7 @@ @interface CountlyConnectionManager ()
1818
1919@property (nonatomic , strong ) NSDate *startTime;
2020@property (nonatomic , assign ) atomic_bool backoff;
21+ @property (nonatomic , assign ) atomic_bool isProcessingQueue;
2122@property (nonatomic , strong ) NSMutableDictionary <NSString *, CLYRequestCallback> *internalRequestCallbacks;
2223@property (nonatomic , strong ) NSMutableArray <CLYQueueFlushRunnable> *queueFlushRunnables;
2324@property (nonatomic ) BOOL hasAnyRequestFailed;
@@ -109,6 +110,7 @@ - (instancetype)init
109110 unsentSessionLength = 0.0 ;
110111 isSessionStarted = NO ;
111112 atomic_init (&_backoff, NO );
113+ atomic_init (&_isProcessingQueue, NO );
112114 _internalRequestCallbacks = [NSMutableDictionary dictionary ];
113115 _queueFlushRunnables = [NSMutableArray array ];
114116 _hasAnyRequestFailed = NO ;
@@ -133,6 +135,7 @@ - (void)resetInstance {
133135 [self ->_queueFlushRunnables removeAllObjects ];
134136 });
135137 _hasAnyRequestFailed = NO ;
138+ atomic_store (&_isProcessingQueue, NO );
136139}
137140
138141- (void )setHost : (NSString *)host
@@ -194,33 +197,37 @@ - (void)proceedOnQueue
194197 return ;
195198 }
196199
197- if (self.connection )
200+ if (self.connection || atomic_exchange (&_isProcessingQueue, YES ) )
198201 {
199202 CLY_LOG_D (@" Proceeding on queue is aborted: Already has a request in process!" );
200203 return ;
201204 }
202-
205+
203206 if (isCrashing)
204207 {
205208 CLY_LOG_D (@" Proceeding on queue is aborted: Application is crashing!" );
209+ atomic_store (&_isProcessingQueue, NO );
206210 return ;
207211 }
208-
212+
209213 if (self.isTerminating )
210214 {
211215 CLY_LOG_D (@" Proceeding on queue is aborted: Application is terminating!" );
216+ atomic_store (&_isProcessingQueue, NO );
212217 return ;
213218 }
214-
219+
215220 if (CountlyPersistency.sharedInstance .isQueueBeingModified )
216221 {
217222 CLY_LOG_D (@" Proceeding on queue is aborted: Queue is being modified!" );
223+ atomic_store (&_isProcessingQueue, NO );
218224 return ;
219225 }
220-
226+
221227 BOOL backoffFlag = atomic_load (&_backoff) ? YES : NO ;
222228 if (backoffFlag) {
223229 CLY_LOG_I (@" %s , currently backed off, skipping proceeding the queue" , __FUNCTION__);
230+ atomic_store (&_isProcessingQueue, NO );
224231 return ;
225232 }
226233
@@ -263,6 +270,7 @@ - (void)proceedOnQueue
263270 // Reset start time and failure flag for future queue processing
264271 self.startTime = nil ;
265272 self.hasAnyRequestFailed = NO ;
273+ atomic_store (&_isProcessingQueue, NO );
266274 return ;
267275 }
268276
@@ -272,17 +280,19 @@ - (void)proceedOnQueue
272280 [CountlyPersistency.sharedInstance removeFromQueue: firstItemInQueue];
273281
274282 [CountlyPersistency.sharedInstance saveToFile ];
275-
283+
284+ atomic_store (&_isProcessingQueue, NO );
276285 [self proceedOnQueue ];
277-
286+
278287 return ;
279288 }
280-
289+
281290
282291 NSString * temporaryDeviceIDQueryString = [NSString stringWithFormat: @" &%@ =%@ " , kCountlyQSKeyDeviceID , CLYTemporaryDeviceID];
283292 if ([firstItemInQueue containsString: temporaryDeviceIDQueryString])
284293 {
285294 CLY_LOG_D (@" Proceeding on queue is aborted: Device ID in request is CLYTemporaryDeviceID!" );
295+ atomic_store (&_isProcessingQueue, NO );
286296 return ;
287297 }
288298
@@ -360,6 +370,7 @@ - (void)proceedOnQueue
360370 self.connection = [self .URLSession dataTaskWithRequest: request completionHandler: ^(NSData * data, NSURLResponse * response, NSError * error)
361371 {
362372 self.connection = nil ;
373+ atomic_store (&self->_isProcessingQueue , NO );
363374 NSDate *endTimeRequest = [NSDate date ];
364375 long duration = (long )[endTimeRequest timeIntervalSinceDate: startTimeRequest];
365376
0 commit comments