Skip to content

Commit 3642b56

Browse files
authored
Delay GDTCORUploadCoordinator timer initial run (#7173)
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.
1 parent 94ab466 commit 3642b56

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

GoogleDataTransport/GDTCORLibrary/GDTCORUploadCoordinator.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ - (void)startTimer {
6868
return;
6969
}
7070

71+
// Delay the timer slightly so it doesn't run while +load calls are still running.
72+
dispatch_time_t deadline = dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC / 2);
73+
7174
self->_timer =
7275
dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, self->_coordinationQueue);
73-
dispatch_source_set_timer(self->_timer, DISPATCH_TIME_NOW, self->_timerInterval,
74-
self->_timerLeeway);
76+
dispatch_source_set_timer(self->_timer, deadline, self->_timerInterval, self->_timerLeeway);
7577

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

0 commit comments

Comments
 (0)