p2 / OAuth2

OAuth2 framework for macOS and iOS, written in Swift.
Other
1.14k stars 276 forks source link

Crash in iOS OAuth2Authorizer #365

Open reggian opened 3 years ago

reggian commented 3 years ago

Hi, I am receiving a crash report via Crashlytics:

OAuth2Authorizer+iOS.swift - Line 154
closure #1 in OAuth2Authorizer.authenticationSessionEmbedded(at:withRedirect:) + 154
Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x1d3011414 __pthread_kill + 8
1  libsystem_pthread.dylib        0x1f0b6cb50 pthread_kill + 272
2  libsystem_c.dylib              0x1ae4efb74 abort + 104
3  libswiftCore.dylib             0x1a9029f20 swift_vasprintf(char**, char const*, char*) + 58
4  libswiftCore.dylib             0x1a902a08c swift::swift_abortDynamicReplacementDisabling() + 54
5  libswiftCore.dylib             0x1a902bffc swift_unownedRetainStrong + 156
6  p2_OAuth2                      0x10333ba2c closure #1 in OAuth2Authorizer.authenticationSessionEmbedded(at:withRedirect:) + 154 (OAuth2Authorizer+iOS.swift:154)
7  p2_OAuth2                      0x10333bf00 thunk for @escaping @callee_guaranteed (@in_guaranteed URL?, @guaranteed Error?) -> () + 4354440960 (<compiler-generated>:4354440960)
8  AuthenticationServices         0x1d725e9c0 __100-[ASWebAuthenticationSession initWithURL:callbackURLScheme:usingEphemeralSession:completionHandler:]_block_invoke + 192
9  SafariServices                 0x1c02adad4 -[SFAuthenticationSession safariViewController:didDecideCookieSharingForURL:shouldCancel:] + 196
10 SafariServices                 0x1c02fe0ac -[SFAuthenticationViewController remoteViewController:didDecideCookieSharingForURL:shouldCancel:] + 116
11 SafariServices                 0x1c035c08c -[SFBrowserRemoteViewController didDecideCookieSharingForURL:shouldCancel:] + 136
12 CoreFoundation                 0x1a50c68f4 __invoking___ + 148
13 CoreFoundation                 0x1a4f9ddf8 -[NSInvocation invoke] + 448
14 libdispatch.dylib              0x1a4cb5db0 _dispatch_client_callout + 20
15 libdispatch.dylib              0x1a4cb9738 _dispatch_block_invoke_direct + 268
16 FrontBoardServices             0x1b4e7e250 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48
17 FrontBoardServices             0x1b4e7dee0 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 448
18 FrontBoardServices             0x1b4e7e434 -[FBSSerialQueue _performNextFromRunLoopSource] + 32
19 CoreFoundation                 0x1a503d76c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
20 CoreFoundation                 0x1a503d668 __CFRunLoopDoSource0 + 208
21 CoreFoundation                 0x1a503c960 __CFRunLoopDoSources0 + 268
22 CoreFoundation                 0x1a5036a8c __CFRunLoopRun + 824
23 CoreFoundation                 0x1a503621c CFRunLoopRunSpecific + 600
24 GraphicsServices               0x1bcc00784 GSEventRunModal + 164
25 UIKitCore                      0x1a7a76ee8 -[UIApplication _run] + 1072
26 UIKitCore                      0x1a7a7c75c UIApplicationMain + 168
27 App                            0x10216ea80 main + 16 (main.m:16)
28 libdyld.dylib                  0x1a4cf66b0 start + 4

The line number is strange, but I think it relates to the oauth2: OAuth2Base property being declared as unowned and accessed in the completion closure after being deallocated.

Using v5.3.1 release.

Jannathbegum23 commented 3 years ago

@reggian Any fix for this issue found

reggian commented 3 years ago

@Jannathbegum23, for now I just captured oauth2 object strongly in the block. But this is a workaround, the issue should probably be fixed by other architecture design decisions. If you want to know specifically what I have done see the commit in my fork of the repo: https://github.com/reggian/OAuth2/commit/cdb58a5cc49d9ab8b3d19f87ee239fc41d39612e.