-
Notifications
You must be signed in to change notification settings - Fork 171
Description
Abstract
Here at Infomaniak we use Matomo across all our Mobile apps and beyond.
Today, Matomo.init() is a locking call that will not return until startDispatchTimer() returns.
startDispatchTimer() Synchronously requires running on the main thread.
I think it would be good practice to wait at least one run loop before the object starts its timers, as they synchronously require running on the main thread.
Issue with Dependency injection
Today, Matomo.init() is a locking call that will not return until startDispatchTimer() returns.
On kDrive, we were trying to make a Matomo instance from a background thread (some event needs to be matomoed).
This Matomo.init() call is made by a dependency injection library in the background
This dependency injection library is simultaneously used, on the main thread, to resole another object.
So it is already blocked at this stage, waiting for the first matomo resolution to finish.
On the Matomo side, the blocking startDispatchTimer() called by the Matomo.init() method does itself perform a DispatchQueue.main.sync{ } that creates a deadlock.
This issue was discovered while opening a deep link to kDrive iOS, it is open source, as well as the DI library used in this particular case.
Proposed solution
PR linked to this issue #476
The minimalist change would be to wait at least one run loop before post init setup is performed.
In #476 I'm using a DispatchQueue.main.async to do so.
I'm not touching any other code, but now the Matomo.init() method will no longer block until it is able to run some code on the Main Thread.
I'm happy to discuss this further, and provide more info if needed.