sentry-cocoa
sentry-cocoa copied to clipboard
Move SessionTracker IO operations to a BG thread
Description
The SentrySessionTracker does a couple of file IO operations on the main thread. Even though they are lightweight, we should consider moving these to a BG thread. We have to ensure that the session tracking logic doesn't end up with race conditions and we have to ensure the logic doesn't break if the app crashes.
It's worth noting that a big customer reported this issue, and we have a customer case for this.
We see a couple of fatal app hangs in our internal SDK crash detection with the stack trace pointing to this root cause
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x1e2ad20c8 write
1 Foundation 0x1909b84c8 write
2 Foundation 0x1909ba6ac closure in writeToFileAux
3 Foundation 0x1909b5da4 NSData._writeData
4 Foundation 0x1909b583c NSData._writeData
5 Sentry.framework 0x104ba21d8 -[SentryFileManager writeData:toPath:] (Sentry.framework:621)
6 Sentry.framework 0x104ba2ccc -[SentryFileManager storeSession:sessionFilePath:] (Sentry.framework:879)
7 Sentry.framework 0x104ba0be4 -[SentryFileManager storeCurrentSession:] (Sentry.framework:308)
8 Sentry.framework 0x104ba8590 -[SentryHub storeCurrentSession:] (Sentry.framework:161)
9 Sentry.framework 0x104ba82a8 -[SentryHub startSession] (Sentry.framework:124)
10 Sentry.framework 0x104bd374c -[SentrySessionTracker startSession]