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 Error::Report function crash #350

Closed
huanghe810229530 opened this issue Aug 13, 2018 · 16 comments
Closed

iOS Error::Report function crash #350

huanghe810229530 opened this issue Aug 13, 2018 · 16 comments
Labels

Comments

@huanghe810229530
Copy link

huanghe810229530 commented Aug 13, 2018

The language of WCDB

Objective-C

The version of WCDB

v1.0.6

The platform of WCDB

iOS

The installation of WCDB

Cocoapods

What's the issue?

As follow: When the query table exists, application in WCDB: : Error: Report function crashed(accidentally). how should solve?

// when app go background, I call this method
- (void)getMembersWithGroupId:(int)groupId resultBlock:(void (^)(NSArray *results))block {
     // otherQueue is a synac queue
    dispatch_async(self.otherQueue, ^{
        NSString *tableName = [NSString stringWithFormat:@"%@_%ld", kTableGroupMember, (long)groupId];
        WCTTable *table = [self.db getTableOfName:tableName withClass:Member.class];
        
        NSArray *res = [table getAllObjects];
        block(res);
    });
}

// Crash info
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00020001013aa660
VM Region Info: 0x20001013aa660 is not in any region. Bytes after previous region: 562946215945825
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
MALLOC_NANO (reserved) 00000001d8000000-00000001e0000000 [128.0M] rw-/rwx SM=NUL ...(unallocated)
--->
UNUSED SPACE AT END

crash

@huanghe810229530
Copy link
Author

@RingoD Help to look at,thanks!

@RingoD
Copy link
Collaborator

RingoD commented Aug 16, 2018

Did you register your own report function?

@huanghe810229530
Copy link
Author

huanghe810229530 commented Aug 16, 2018

I just do this:

+(DBManager*)sharedDBMagnger {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedDBMagnger = [[DBManager alloc]init];
        sharedDBMagnger.messageQueue = dispatch_queue_create("db_message_queue", NULL);
        sharedDBMagnger.otherQueue = dispatch_queue_create("db_other_queue", NULL);
        [WCTStatistics SetGlobalErrorReport:^(WCTError *error) {
            DEBUGLog(@"[WCDB]%@", error);
        }];
    });
    
    return sharedDBMagnger;
}

Is there a problem with this?

@RingoD
Copy link
Collaborator

RingoD commented Aug 17, 2018

It seems like nothing wrong. Can you provide a reproducible project for this issue?

@huanghe810229530
Copy link
Author

The probability of this problem is very low. Development have not seen, but the online version appeared several times.

@RingoD
Copy link
Collaborator

RingoD commented Aug 17, 2018

Em... I have no idea about this. There is no same crash for us. Maybe we should wait for more information.

@huanghe810229530
Copy link
Author

Ok, I will collect the new information, if have I will tell you.

@highlystuff
Copy link

I met this issue,too... any solution?

@liufengdev
Copy link

The same for me, any solution?

@liufengdev
Copy link

liufengdev commented May 27, 2019

After a very thorough review, i have found that where there is a crash like this, there is also a [db close] operation (the reason for [db close] is trying to reduce size of wal file, maybe i was wrong), about 99%. So i review the document, remove all [db close] operation, and use journal_size_limit instead to reach my purpose.

@liufengdev
Copy link

In wcdb, default value for journal_size_limit is -1, which means NO LIMIT (https://www.sqlite.org/pragma.html#pragma_journal_size_limit).

@RingoD
Copy link
Collaborator

RingoD commented May 28, 2019

@liufengdev Hi. I read your comment and confuse that why do you think this crash is related to close? Did you have any evidence?

@liufengdev
Copy link

liufengdev commented Jun 11, 2019

@RingoD

  1. Just a try without evidence and actually this crash has NO matter with close.
  2. Today, we find a way to reproduce it, just deliberately kill you app via double click home button and swap up. While you doing this, Main Thread will clean all static shared_ptr, and deconstruct them, the question is, at this time , some other thread may be accessing data from shared_ptr. Moreover, this is the evidence for Thread Safety with some parts in WCDB, see https://pastebin.com/NQxBUbrE

What happens when we deliberately kill our app?

` thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 7.1

frame #0: 0x000000010ea28d20 msgInHouse`WCDB::Error::ReportMethodObj::~ReportMethodObj(this=0x0000600000c21560) at error.cpp:75:9
frame #1: 0x000000010ea28d85 msgInHouse`WCDB::Error::ReportMethodObj::~ReportMethodObj(this=0x0000600000c21560) at error.cpp:74:48
frame #2: 0x000000010ea31feb msgInHouse`std::__1::default_delete<WCDB::Error::ReportMethodObj>::operator(this=0x00006000002210b8, __ptr=0x0000600000c21560)(WCDB::Error::ReportMethodObj*) const at memory:2335:5
frame #3: 0x000000010ea31c80 msgInHouse`std::__1::__shared_ptr_pointer<WCDB::Error::ReportMethodObj*, std::__1::default_delete<WCDB::Error::ReportMethodObj>, std::__1::allocator<WCDB::Error::ReportMethodObj> >::__on_zero_shared(this=0x00006000002210a0) at memory:3636:5
frame #4: 0x000000010ea2e9da msgInHouse`std::__1::__shared_count::__release_shared(this=0x00006000002210a0) at memory:3540:9
frame #5: 0x000000010ea2e97f msgInHouse`std::__1::__shared_weak_count::__release_shared(this=0x00006000002210a0) at memory:3582:27
frame #6: 0x000000010ea2e94c msgInHouse`std::__1::shared_ptr<WCDB::Error::ReportMethodObj>::~shared_ptr(this=0x00000001124a5ab8) at memory:4518:19
frame #7: 0x000000010ea28c45 msgInHouse`std::__1::shared_ptr<WCDB::Error::ReportMethodObj>::~shared_ptr(this=0x00000001124a5ab8) at memory:4516:1
frame #8: 0x000000011f6a5d35 libsystem_c.dylib`__cxa_finalize_ranges + 319
frame #9: 0x000000011f6a6068 libsystem_c.dylib`exit + 48
frame #10: 0x0000000128103b57 UIKitCore`-[UIApplication _terminateWithStatus:] + 276
frame #11: 0x000000012794229a UIKitCore`__98-[__UICanvasLifecycleMonitor_Compatability deactivateEventsOnly:withContext:forceExit:completion:]_block_invoke.261 + 330
frame #12: 0x0000000128107cc9 UIKitCore`_runAfterCACommitDeferredBlocks + 318
frame #13: 0x00000001280f7199 UIKitCore`_cleanUpAfterCAFlushAndRunDeferredBlocks + 358
frame #14: 0x000000012812432b UIKitCore`_afterCACommitHandler + 124
frame #15: 0x0000000117ab00f7 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
frame #16: 0x0000000117aaa5be CoreFoundation`__CFRunLoopDoObservers + 430
frame #17: 0x0000000117aaac31 CoreFoundation`__CFRunLoopRun + 1505
frame #18: 0x0000000117aaa302 CoreFoundation`CFRunLoopRunSpecific + 626
frame #19: 0x00000001201b72fe GraphicsServices`GSEventRunModal + 65
frame #20: 0x00000001280fcba2 UIKitCore`UIApplicationMain + 140
frame #21: 0x000000010c3469f0 msgInHouse`main(argc=1, argv=0x00007ffee38ba018) at main.m:14:16
frame #22: 0x000000011f5be541 libdyld.dylib`start + 1
frame #23: 0x000000011f5be541 libdyld.dylib`start + 1`

Wish all above will help.

ReportMethodObj is just a wrapper for ReportMethod, only used for debug.

class ReportMethodObj { public: ReportMethod func; ReportMethodObj(ReportMethod func); ~ReportMethodObj(); };

@liufengdev
Copy link

liufengdev commented Jun 18, 2019

Moreover, on June 17,2019

https://developer.apple.com/documentation/xcode_release_notes/xcode_11_beta_2_release_notes,
Clang now provides a mechanism for controlling exit-time destructor registration

@liufengdev
Copy link

@huanghe810229530 The compiler flag -fno-c++-static-destructors works [Xcode 10.2].

@RingoD
Copy link
Collaborator

RingoD commented Jul 31, 2019

@liufengdev Yes, -fno-c++-static-destructors will be added to the compiler options. But I didn't know that it's already supported since Xcode 10.2. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants