Skip to content

Commit

Permalink
Delay GDTCORUploadCoordinator timer initial run (#7173)
Browse files Browse the repository at this point in the history
If an upload coordinator gets created during `+load` calls, it can end up running its immediately, while +load calls are still running. It's generally a bad idea to be splitting off threads while +load calls are still running.

The upload coordinator checks every 30 seconds, and doesn't really need to run right away. Since it's easy to transitively create an upload coordinator from other calls that happen during +load, we'll just push off the initial run of the timer slightly. That makes it less likely to interfere (or deadlock) with other load calls.

See #7171 for an example of a problem solved by this change.
  • Loading branch information
bjhomer authored Dec 15, 2020
1 parent 94ab466 commit 3642b56
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions GoogleDataTransport/GDTCORLibrary/GDTCORUploadCoordinator.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ - (void)startTimer {
return;
}

// Delay the timer slightly so it doesn't run while +load calls are still running.
dispatch_time_t deadline = dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC / 2);

self->_timer =
dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, self->_coordinationQueue);
dispatch_source_set_timer(self->_timer, DISPATCH_TIME_NOW, self->_timerInterval,
self->_timerLeeway);
dispatch_source_set_timer(self->_timer, deadline, self->_timerInterval, self->_timerLeeway);

dispatch_source_set_event_handler(self->_timer, ^{
if (![[GDTCORApplication sharedApplication] isRunningInBackground]) {
Expand Down

0 comments on commit 3642b56

Please sign in to comment.