Sentry fails to write report to disk with concurrent fatal crashes
Platform
macOS
Installed
Swift Package Manager
Version
8.10.0
Steps to Reproduce
- Create a code that triggers multiple simultaneous Tasks, each one calling
fatalError(). Ensure that they are not restricted to run in the MainActor, so they can run concurrently. For example:
AsyncStream { continuation in
Task {
await withTaskGroup(of: Void.self) { group in
for key in [“key1”, “key2”, “key3”, “key4”, “key5”, “key6”] {
group.addTask {
fatalError("Testing")
continuation.yield(key)
}
}
}
continuation.finish()
}
}
- When the code above is executed, the app crashes, but Sentry does NOT generate any report. When Sentry debug is enabled, this is what is printed:
ImageCache/ImageCache.swift:56: Fatal error: Testing
ImageCache/ImageCache.swift:56: Fatal error: Testing
ImageCache/ImageCache.swift:56: Fatal error: Testing
ImageCache/ImageCache.swift:56: Fatal error: Testing
ImageCache/ImageCache.swift:56: Fatal error: Testing
ImageCache/ImageCache.swift:56: Fatal error: Testing
ERROR: SentryCrashReport.c (1487): void sentrycrashreport_writeRecrashReport(const SentryCrash_MonitorContext *const, const char *const): Could not rename to : No such file or directory
ERROR: SentryCrashFileUtils.c (414): _Bool sentrycrashfu_openBufferedWriter(SentryCrashBufferedWriter *, const char *const, char *, int): Could not open crash report file : No such file or directory
Trace/BPT trap: 5
If the code above is restricted to run on a single actor, for example by moving the addTask closure to a function marked as @MainActor, they will run serially, the app will crash once and stop, and Sentry will have a chance to save the crash report to disk successfully.
My naive understanding is that Sentry’s file operations should only execute in the main thread or at least be better shielded for concurrent executions.
Actual Result
Sentry code crashes and no crash report is stored in disk:
ERROR: SentryCrashReport.c (1487): void sentrycrashreport_writeRecrashReport(const SentryCrash_MonitorContext *const, const char *const): Could not rename to : No such file or directory
ERROR: SentryCrashFileUtils.c (414): _Bool sentrycrashfu_openBufferedWriter(SentryCrashBufferedWriter *, const char *const, char *, int): Could not open crash report file : No such file or directory
Trace/BPT trap: 5
Expected Result
App crashes in the first fatalError and Sentry saves the crash report to disk.
Are you willing to submit a PR?
If given some guidance on how to fix it, yes.
@mangini thank you for reporting and the details - we will investigate and try to reproduce
I was able to reproduce this. Now we need to find a way to solve it.
I've experienced the same issues in a highly parallelized app. If the crash occurs in a Task, it often will not be reported