Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Crashed: com.apple.main-thread #276

Closed
r0b0t3d opened this issue Feb 28, 2020 · 24 comments
Closed

[iOS] Crashed: com.apple.main-thread #276

r0b0t3d opened this issue Feb 28, 2020 · 24 comments

Comments

@r0b0t3d
Copy link
Contributor

r0b0t3d commented Feb 28, 2020

I got this crash today via Crashlytics. It seems we must to handle the code in didPickDocumentsAtURLs on main thread.

Crashed: com.apple.main-thread
0  Stuneo                         0x1050e13b0 -[RNDocumentPicker documentPicker:didPickDocumentsAtURLs:] + 167 (RNDocumentPicker.m:167)
1  UIKitCore                      0x1a03f3384 __74-[UIDocumentPickerViewController _callDelegateWithSelectedURLsAndDismiss:]_block_invoke + 128
2  UIKitCore                      0x1a037124c -[UIViewController dismissViewControllerWithTransition:completion:] + 1236
3  UIKitCore                      0x1a0389128 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 264
4  UIKitCore                      0x1a0385874 -[_UIViewControllerTransitionContext _runAlongsideCompletions] + 132
5  UIKitCore                      0x1a03855b8 -[_UIViewControllerTransitionContext completeTransition:] + 116
6  UIKitCore                      0x1a0dcbfe0 -[UITransitionView notifyDidCompleteTransition:] + 240
7  UIKitCore                      0x1a0dcbc8c -[UITransitionView _didCompleteTransition:] + 1132
8  UIKitCore                      0x1a0e01d90 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 588
9  UIKitCore                      0x1a0dd5c70 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 244
10 UIKitCore                      0x1a0dd6178 -[UIViewAnimationState animationDidStop:finished:] + 240
11 UIKitCore                      0x1a0dd62c8 -[UIViewAnimationState animationDidStop:finished:] + 576
12 QuartzCore                     0x1a3387dac CA::Layer::run_animation_callbacks(void*) + 276
13 libdispatch.dylib              0x19c5bf184 _dispatch_client_callout + 16
14 libdispatch.dylib              0x19c571190 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1044
15 CoreFoundation                 0x19c8705e4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
16 CoreFoundation                 0x19c86b5d8 __CFRunLoopRun + 2004
17 CoreFoundation                 0x19c86aadc CFRunLoopRunSpecific + 464
18 GraphicsServices               0x1a680b328 GSEventRunModal + 104
19 UIKitCore                      0x1a097863c UIApplicationMain + 1936
20 Stuneo                         0x104a48864 main + 14 (main.m:14)
21 libdyld.dylib                  0x19c6f4360 start + 4
@vonovak
Copy link
Collaborator

vonovak commented Mar 12, 2020

hello and thanks for reporting; from what do you infer that the method must be called on the main thread? Thanks.

@r0b0t3d
Copy link
Contributor Author

r0b0t3d commented Mar 12, 2020

As you can see in the crash log, it issued at didPickDocumentsAtURLs

@vonovak
Copy link
Collaborator

vonovak commented Mar 12, 2020

@r0b0t3d yes, I see that, but I'm just asking why exactly running on the main thread is the right fix for the issue. I'm not an experienced ios "stacktrace reader" :) Thanks.

@r0b0t3d
Copy link
Contributor Author

r0b0t3d commented Mar 13, 2020

@vonovak I did double check the crash on crashlytics

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000010

0  Stuneo                         0x1050e13b0 -[RNDocumentPicker documentPicker:didPickDocumentsAtURLs:] + 167 (RNDocumentPicker.m:167)

that point to this line in RNDocumentPicker.m

resolve(results);

Basically, this crash indicate that we are accessing an deallocated object. Any chances that resolve are deallocated?

@chgsilva
Copy link

i am having the same issue. Any solutions?

@tekmin
Copy link

tekmin commented May 15, 2020

Same here, any solution here?

@phatmann
Copy link

phatmann commented Jun 9, 2020

This crash happens if you tap on the same file multiple times in rapid succession. The resolve object is null, probably because composeResolvers is accessed in a non thread-safe manner.

@r0b0t3d
Copy link
Contributor Author

r0b0t3d commented Jun 14, 2020

@phatmann could you reproduce the issue? I tried multiple times on iOS 12.4 (simulator) and 13.5 (simulator + real device) but can not reproduce.

@phatmann
Copy link

phatmann commented Jun 14, 2020 via email

@vonovak
Copy link
Collaborator

vonovak commented Jun 14, 2020

@phatmann would you please share the output of your react-native info command + any extra stuff potentially worth mentioning? I cannot reproduce either. Thank you!

@hungps
Copy link

hungps commented Jun 15, 2020

I'm having the same problem when fast tapping the file multiple times (iPhone X, ios 13.3, real device). Any quick fix/patch?

@r0b0t3d
Copy link
Contributor Author

r0b0t3d commented Jun 15, 2020

@hungps-2150 My quick thought is that didPickDocumentsAtURLs will be called multiple time.
In the first time, resolve was removed by calling [composeResolvers removeLastObject].
So in the second time, resolve will be nil when getting [composeResolvers lastObject].

It is easy for you because you can reproduce the issue. Could you please help to confirm that how many time didPickDocumentsAtURLs was called by adding simple log? And check null for resolve after getting it.

It is something like

- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls
{
    NSLog(@"didPickDocumentsAtURLs");
    if (controller.documentPickerMode == UIDocumentPickerModeImport) {
        RCTPromiseResolveBlock resolve = [composeResolvers lastObject];
        RCTPromiseRejectBlock reject = [composeRejecters lastObject];
        [composeResolvers removeLastObject];
        [composeRejecters removeLastObject];
        
        if (resolve == nil) {
            return;
        }
        NSMutableArray *results = [NSMutableArray array];
        for (id url in urls) {
            NSError *error;
            NSMutableDictionary* result = [self getMetadataForUrl:url error:&error];
            if (result) {
                [results addObject:result];
            } else {
                reject(E_INVALID_DATA_RETURNED, error.localizedDescription, error);
                return;
            }
        }
        
        resolve(results);
    }
}

@hungps
Copy link

hungps commented Jun 15, 2020

@r0b0t3d I tried your code and didPickDocumentsAtURLs fires 2 times

@r0b0t3d
Copy link
Contributor Author

r0b0t3d commented Jun 15, 2020

@scitbiz thanks for quick update. Finally we found the root cause :D.
So did it crash when you running above code?

@hungps
Copy link

hungps commented Jun 15, 2020

@r0b0t3d no but I'm currently using react-native-navigation and it pops back to the previous screen after selecting. If I'm not using your code (checking for nil), it pops back and then crashes

@r0b0t3d
Copy link
Contributor Author

r0b0t3d commented Jun 15, 2020

@scitbiz It feel like the above code works as expected (no crash).
In both case, your app works the same (pops back). Please correct if I am missing something!

@hungps
Copy link

hungps commented Jun 15, 2020

@r0b0t3d yes, exactly!

@vonovak
Copy link
Collaborator

vonovak commented Jun 15, 2020

hi, thanks for the comments, I suspected this would be the case but found it weird that I could not reproduce it. I'll try to fix this soon by extracting the promise logic into separate class.

phatmann added a commit to nextforce/react-native-document-picker that referenced this issue Jun 16, 2020
@ghost
Copy link

ghost commented Aug 6, 2020

Hi, I checked this thread recently and updated react-native-document-picker to version: 3.5.4, (IOS 13.5 in simulator), unfortunately still getting this error on tapping the same file multiple times in rapid succession.

@lucasftcruz
Copy link

lucasftcruz commented Sep 8, 2020

I looked at the source code for 3.5.4 and also previous versions and I couldn't find @phatmann changes. Any idea when a new version will be published with this fix?

@r0b0t3d
Copy link
Contributor Author

r0b0t3d commented Sep 9, 2020

@PointCodeZero Fixed from @phatmann is on his repo. As @vonovak said above, he will fix this issue.
While waiting the fix, you could easily apply above workaround by using patch-package and edit the code in RNDocumentPicker.m and add this check

        if (resolve == nil) {
            return;
        }

@0x01001
Copy link

0x01001 commented Sep 16, 2020

Same here, when show document picker I change to google drive and touch many time on a picture -> delay closing -> crash app.

Here my log:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000010
VM Region Info: 0x10 is not in any region.  Bytes before following region: 4301455344
      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                 0000000100630000-0000000100644000 [   80K] r-x/r-x SM=COW  ...app/bitcastle

Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   react_native_document_picker  	0x000000010268686c 0x102680000 + 26732
1   react_native_document_picker  	0x0000000102686850 0x102680000 + 26704
2   UIKitCore                     	0x00000001b697f384 __74-[UIDocumentPickerViewController _callDelegateWithSelectedURLsAndDismiss:]_block_invoke + 128
3   UIKitCore                     	0x00000001b68fd24c -[UIViewController dismissViewControllerWithTransition:completion:] + 1236
4   UIKitCore                     	0x00000001b6915128 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 264
5   UIKitCore                     	0x00000001b6911874 -[_UIViewControllerTransitionContext _runAlongsideCompletions] + 132
6   UIKitCore                     	0x00000001b69115b8 -[_UIViewControllerTransitionContext completeTransition:] + 116
7   UIKitCore                     	0x00000001b7357fe0 -[UITransitionView notifyDidCompleteTransition:] + 240
8   UIKitCore                     	0x00000001b7357c8c -[UITransitionView _didCompleteTransition:] + 1132
9   UIKitCore                     	0x00000001b738dd90 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 588
10  UIKitCore                     	0x00000001b7361c70 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 244
11  UIKitCore                     	0x00000001b7362178 -[UIViewAnimationState animationDidStop:finished:] + 240
12  UIKitCore                     	0x00000001b73622c8 -[UIViewAnimationState animationDidStop:finished:] + 576
13  QuartzCore                    	0x00000001b9913dac CA::Layer::run_animation_callbacks+ 1453484 (void*) + 276
14  libdispatch.dylib             	0x00000001b2b4b184 _dispatch_client_callout + 16
15  libdispatch.dylib             	0x00000001b2afd190 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1044
16  CoreFoundation                	0x00000001b2dfc5e4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
17  CoreFoundation                	0x00000001b2df75d8 __CFRunLoopRun + 2004
18  CoreFoundation                	0x00000001b2df6adc CFRunLoopRunSpecific + 464
19  GraphicsServices              	0x00000001bcd97328 GSEventRunModal + 104
20  UIKitCore                     	0x00000001b6f0463c UIApplicationMain + 1936

set0gut1 pushed a commit to newn-team/react-native-document-picker that referenced this issue Dec 25, 2020
@wikramdas
Copy link

@PointCodeZero Fixed from @phatmann is on his repo. As @vonovak said above, he will fix this issue.
While waiting the fix, you could easily apply above workaround by using patch-package and edit the code in RNDocumentPicker.m and add this check

        if (resolve == nil) {
            return;
        }

I also were facing this issue and lost my day on this issue.
You saved my another day. This solution worked for me.
Thanks

retyui added a commit to retyui/react-native-document-picker that referenced this issue Feb 2, 2021
@retyui retyui mentioned this issue Feb 2, 2021
3 tasks
vonovak pushed a commit that referenced this issue Feb 2, 2021
@retyui
Copy link
Contributor

retyui commented Feb 3, 2021

The fix was added in 4.3.0

@vonovak could it be closed this issue?

@vonovak vonovak closed this as completed Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants