sparkle-project / Sparkle

A software update framework for macOS
https://sparkle-project.org
Other
7.37k stars 1.05k forks source link

Assertion failed when bundle has disappeared: auxiliaryToolURL != nil #2435

Closed kdrag0n closed 1 year ago

kdrag0n commented 1 year ago

Summary

I saw this rare crash in the wild:

OS Version: macOS 13.4.1 (22F82)
Report Version: 104

Exception Type: EXC_CRASH (SIGABRT)
Crashed Thread: 0

Application Specific Information:
Assertion failed: (auxiliaryToolURL != nil), function -[SUInstallerLauncher pathForBundledTool:extension:fromBundle:], file SUInstallerLauncher.m, line 329.
 > auxiliaryToolURL != nil > SUInstallerLauncher.m

Thread 0 Crashed:
0   libsystem_kernel.dylib          0x31fb1f724         __pthread_kill
1   libsystem_pthread.dylib         0x31fb90c24         pthread_kill
2   libsystem_c.dylib               0x31f93cae4         abort
3   libsystem_c.dylib               0x31f93be40         __assert_rtn
4   Sparkle                         0x100e4b464         SPUMakeUserAgentWithHost
5   Sparkle                         0x100e42288         <redacted>
6   Sparkle                         0x100e426d8         SPUSystemNeedsAuthorizationAccessForBundlePath
7   libdispatch.dylib               0x31f832870         _dispatch_call_block_and_release
8   libdispatch.dylib               0x31f8343fc         _dispatch_client_callout
9   libdispatch.dylib               0x31f842bf4         _dispatch_main_queue_drain
10  libdispatch.dylib               0x31f842844         _dispatch_main_queue_callback_4CF
11  CoreFoundation                  0x31fd16c50         __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
12  CoreFoundation                  0x31fcd43d0         __CFRunLoopRun
13  CoreFoundation                  0x31fcd34b4         CFRunLoopRunSpecific
14  HIToolbox                       0x332db4c3c         RunCurrentEventLoopInMode
15  HIToolbox                       0x332db4a78         ReceiveNextEventCommon
16  HIToolbox                       0x332db47d0         _BlockUntilNextEventMatchingListInModeWithFilter
17  AppKit                          0x32615ad40         _DPSNextEvent
18  AppKit                          0x326159edc         -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
19  AppKit                          0x3267fe444         _NSHLTBMenuEventProc
20  HIToolbox                       0x332e19be4         IsUserStillTracking
21  HIToolbox                       0x332f59680         TrackMenuCommon
22  HIToolbox                       0x332e24a5c         MenuSelectCore
23  HIToolbox                       0x332e24850         _HandleMenuSelection2
24  AppKit                          0x3262accf0         _NSHandleCarbonMenuEvent
25  AppKit                          0x3262acb14         _DPSEventHandledByCarbon
26  AppKit                          0x32615a4c8         -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
27  AppKit                          0x32614e340         -[NSApplication run]
28  AppKit                          0x326125790         NSApplicationMain
29  SwiftUI                         0x37023b6b4         OUTLINED_FUNCTION_8
30  SwiftUI                         0x37139c5a8         OUTLINED_FUNCTION_14
31  SwiftUI                         0x370c1cc44         OUTLINED_FUNCTION_1

Another case:

OS Version: macOS 13.5.0 (22G74)
Report Version: 104

Exception Type: EXC_CRASH (SIGABRT)
Crashed Thread: 0

Application Specific Information:
-[SUInstallerLauncher pathForBundledTool:extension:fromBundle:] > Assertion failed: (auxiliaryToolURL != nil), function -[SUInstallerLauncher pathForBundledTool:extension:fromBundle:], file SUInstallerLauncher.m, line 329.

Thread 0 Crashed:
0   libsystem_kernel.dylib          0xfff009582202      __pthread_kill
1   libsystem_c.dylib               0xfff0093c7b44      abort
2   libsystem_c.dylib               0xfff0093c6e5d      __assert_rtn
3   Sparkle                         0x10f100067         SPUMakeUserAgentWithHost
4   Sparkle                         0x10f0f591f         <redacted>
5   Sparkle                         0x10f0f5e1e         SPUSystemNeedsAuthorizationAccessForBundlePath
6   libdispatch.dylib               0xfff0092b3d90      _dispatch_call_block_and_release
7   libdispatch.dylib               0xfff0092b5032      _dispatch_client_callout
8   libdispatch.dylib               0xfff0092c1fce      _dispatch_main_queue_drain
9   libdispatch.dylib               0xfff0092c1c06      _dispatch_main_queue_callback_4CF
10  CoreFoundation                  0xfff009774205      __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
11  CoreFoundation                  0xfff009733f2f      __CFRunLoopRun
12  CoreFoundation                  0xfff009732f31      CFRunLoopRunSpecific
13  HIToolbox                       0xfff01cc80f3c      RunCurrentEventLoopInMode
14  HIToolbox                       0xfff01cc80d4d      ReceiveNextEventCommon
15  HIToolbox                       0xfff01cc80aa7      _BlockUntilNextEventMatchingListInModeWithFilter
16  AppKit                          0xfff00f8a825b      _DPSNextEvent
17  AppKit                          0xfff00f8a7105      -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
18  AppKit                          0xfff00f899787      -[NSApplication run]
19  AppKit                          0xfff00f86d9a0      NSApplicationMain
20  SwiftUI                         0xfff21df0a9fa      block_destroy_helper.89
21  SwiftUI                         0xfff21ef478b3      __swift_memcpy171_8
22  SwiftUI                         0xfff21e8606ce      objectdestroyTm

I suspect that this happens when people delete the app bundle while it's running (perhaps with rm -rf) and later try to apply an update.

Potential Fix

It might be worth showing an error alert instead of crashing in this case.

Version

v2.4.2

zorgiepoo commented 1 year ago

Do you have the full crash log files or at least the base address of Sparkle in the report (assuming you are using one of our pre-built distributions of Sparkle). The backtrace doesn't make a whole lot of sense, although the assert does seem convincing.

zorgiepoo commented 1 year ago

In any case, moving or mutating the app bundle while it's moving is not really supported. Even if I could simulate reproducing this issue (which I have not been able to) and make it fail gracefully, any other point of your app or Sparkle could fail badly later.

More interesting to figure out is why this is happening and then how to address the root problem, but I suspect that will be difficult.

zorgiepoo commented 1 year ago

I guess it doesn't hurt to make this fail gracefully, why not.

kdrag0n commented 1 year ago

Right, I'm not sure how to reproduce it either but in the past I've seen Bundle.path(forAuxiliaryExecutable:) return nil in cases like this, so I started using "\(Bundle.main.bundlePath)/Contents/MacOS/\(name)" instead to fix the issue in my app's code.

I'm using SwiftPM so I think it's built from source, but here are the raw addresses:

Thread 0 Crashed:
0   libsystem_kernel.dylib          0xfff00d0511f2      0xfff00d049000 + 10
1   libsystem_c.dylib               0xfff00ce96b44      0xfff00ce17000 + 122
2   libsystem_c.dylib               0xfff00ce95e5d      0xfff00ce17000 + 313
3   Sparkle                         0x10884c157         0x10881a000 + 8713
4   Sparkle                         0x108841aff         0x10881a000 + 4437842687
5   Sparkle                         0x108841ffe         0x10881a000 + 1269
6   libdispatch.dylib               0xfff00cd82d90      0xfff00cd81000 + 11
7   libdispatch.dylib               0xfff00cd84032      0xfff00cd81000 + 7
8   libdispatch.dylib               0xfff00cd90fce      0xfff00cd81000 + 953
9   libdispatch.dylib               0xfff00cd90c06      0xfff00cd81000 + 30
10  CoreFoundation                  0xfff00d243235      0xfff00d187000 + 9
11  CoreFoundation                  0xfff00d20306f      0xfff00d187000 + 2452
12  CoreFoundation                  0xfff00d202071      0xfff00d187000 + 560
13  HIToolbox                       0xfff02071ffcc      0xfff0206f1000 + 291
14  HIToolbox                       0xfff02071fddd      0xfff0206f1000 + 656
15  HIToolbox                       0xfff02071fb37      0xfff0206f1000 + 63
16  AppKit                          0xfff01336379f      0xfff013325000 + 857
17  AppKit                          0xfff013362649      0xfff013325000 + 1213
18  AppKit                          0xfff013354cb7      0xfff013325000 + 585
19  AppKit                          0xfff013328ed1      0xfff013325000 + 816
20  SwiftUI                         0xfff221916cba      0xfff221891000 + 13712
21  SwiftUI                         0xfff22294ff43      0xfff221891000 + 27163
22  SwiftUI                         0xfff22226c3ae      0xfff221891000 + 47121
Binary Images:
0x10881a000 - 0x10885dfff Sparkle x86  <5a4580eea89034fe89d1b9a730e89621> /Applications/OrbStack.app/Contents/Frameworks/Sparkle.framework/Versions/B/Sparkle

Let me know if I should try to symbolicate it manually.

zorgiepoo commented 1 year ago

I'm using SwiftPM so I think it's built from source

Actually we provide a prebuilt binary distribution.

The offsets in that backtrace are kind of sad again :(.

In any case, I'm just going to address this by failing more gracefully. I'm not too convinced to work around Bundle.path(forAuxiliaryExecutable:) not being "reliable". NSBundle doesn't support bundles moving around, though.

kdrag0n commented 1 year ago

Makes sense, thanks for the quick fix/workaround!