Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #493 from MatkovIvan/fix/deadlock
Browse files Browse the repository at this point in the history
Fix deadlock
  • Loading branch information
Benjamin Scholtysik (Reimold) authored Dec 13, 2017
2 parents c97cb5e + 23af55b commit 017f55f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Classes/BITChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 017f55f

Please sign in to comment.