From 23af55b608dd625cf4c8336b48442ef2317a912f Mon Sep 17 00:00:00 2001 From: Ivan Matkov Date: Thu, 14 Dec 2017 00:51:27 +0300 Subject: [PATCH] Fix deadlock --- Classes/BITChannel.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Classes/BITChannel.m b/Classes/BITChannel.m index 01e0a721..a589c0d3 100644 --- a/Classes/BITChannel.m +++ b/Classes/BITChannel.m @@ -293,14 +293,16 @@ - (void)enqueueTelemetryItem:(BITTelemetryData *)item completionHandler:(nullabl return; } + // Should be outside of @synchronized block! + BOOL applicationIsInBackground = ([BITHockeyHelper applicationState] == BITApplicationStateBackground); + // Enqueue item. @synchronized(self) { NSDictionary *dict = [strongSelf dictionaryForTelemetryData:item]; [strongSelf appendDictionaryToEventBuffer:dict]; + // If the app is running in the background. - BOOL applicationIsInBackground = ([BITHockeyHelper applicationState] == BITApplicationStateBackground); - if (strongSelf.dataItemCount >= strongSelf.maxBatchSize || - (applicationIsInBackground)) { + if (strongSelf.dataItemCount >= strongSelf.maxBatchSize || applicationIsInBackground) { // Case 2: Max batch count has been reached or the app is running in the background, so write queue to disk and delete all items. [strongSelf persistDataItemQueue:&BITTelemetryEventBuffer];