Skip to content

Commit

Permalink
Rework the background task service shutdown procedure to give more he…
Browse files Browse the repository at this point in the history
…adroom against the 5s ANR timeout
  • Loading branch information
kstenerud committed Mar 15, 2022
1 parent a75e2d7 commit e17d3da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,13 @@ internal class BackgroundTaskService(
internalReportExecutor.shutdownNow()
defaultExecutor.shutdownNow()

// shutdown the error/session executors first, waiting for existing tasks to complete.
// If a request fails it may perform IO to persist the payload for delivery next launch,
// which would submit tasks to the IO executor - therefore it's critical to
// shutdown the IO executor last.
// Wait a little while for these ones to shut down
errorExecutor.shutdown()
sessionExecutor.shutdown()
ioExecutor.shutdown()

errorExecutor.awaitTerminationSafe()
sessionExecutor.awaitTerminationSafe()

// shutdown the IO executor last, waiting for any existing tasks to complete
ioExecutor.shutdown()
ioExecutor.awaitTerminationSafe()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class LaunchCrashDeliveryTest {
payload: EventPayload,
deliveryParams: DeliveryParams
): DeliveryStatus {
Thread.sleep(3000)
Thread.sleep(2000)
count.getAndIncrement()
return DeliveryStatus.DELIVERED
}
Expand Down

0 comments on commit e17d3da

Please sign in to comment.