diff --git a/Bugsnag/Helpers/BSGRunContext.m b/Bugsnag/Helpers/BSGRunContext.m index 50742b339..401996bb2 100644 --- a/Bugsnag/Helpers/BSGRunContext.m +++ b/Bugsnag/Helpers/BSGRunContext.m @@ -259,11 +259,16 @@ static void NoteThermalState(__unused CFNotificationCenterRef center, __unused CFNotificationName name, const void *object, __unused CFDictionaryRef userInfo) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunguarded-availability-new" - bsg_runContext->thermalState = ((__bridge NSProcessInfo *)object).thermalState; -#pragma clang diagnostic pop - BSGRunContextUpdateTimestamp(); + if (@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)) { + // Workaround for iOS 15.0.2 to 15.1.1: Foundation in rare cases posts + // ThermalStateDidChangeNotification from within -[NSProcessInfo thermalState], + // causing recursion and a crash via _os_unfair_lock_recursive_abort(). + // To avoid this, grab the new thermal state asynchronously. + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + bsg_runContext->thermalState = ((__bridge NSProcessInfo *)object).thermalState; + BSGRunContextUpdateTimestamp(); + }); + } } #if BSG_HAVE_OOM_DETECTION