Assertion failure in CBLModel.m:461

117 views
Skip to first unread message

Christoph Berlin

unread,
Nov 9, 2014, 1:25:09 PM11/9/14
to mobile-c...@googlegroups.com
Hi,
we are kind of stuck on a problem we cannot explain. Sometimes (not always) we get the following error:

*** Assertion failure in -[OPUserProfile setValue:ofProperty:], /Users/jenkins/jenkins/workspace/build_cblite_ios_102-enterprise/couchbase-lite-ios/Source/API/CBLModel.m:461


Our problem is that the issue occurs randomly - it works about 50% of the time (same functions) while other times it fails. Debugging the issue leads to nowhere.


Does anyone have an idea of what could be the cause?


The OPProfilefunction does nothing fancy but we know that it fails at 


self.user_id = user_id;
 


- (instancetype) initCurrentUserProfileInDatabase: (CBLDatabase*)db andUserID:(NSString*)user_id;

{

    NSParameterAssert(user_id);

    CBLDocument *doc = [db documentWithID:[@"profile:" stringByAppendingString:user_id]];

    self = [super initWithDocument:doc];

    if (self)

    {

        self.user_id = user_id;

        self.type = kOPDocType_UserProfile;

        self.created_at = [NSDate date];

    }

    return self;

}


Message has been deleted

Christoph Berlin

unread,
Nov 9, 2014, 2:06:25 PM11/9/14
to mobile-c...@googlegroups.com
We actually got further in trouble shooting the issue yet we don't know what the root cause is:

2014-11-09 11:04:25.471 OnePlan[10513:214282] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: _document'

*** First throw call stack:

(

0   CoreFoundation                      0x0000000110e99f35 __exceptionPreprocess + 165

1   libobjc.A.dylib                     0x00000001106f7bb7 objc_exception_throw + 45

2   CoreFoundation                      0x0000000110e99d9a +[NSException raise:format:arguments:] + 106

3   Foundation                          0x000000010dc2a5df -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195

4   OnePlan                             0x000000010cc54b70 -[CBLModel setValue:ofProperty:] + 199

5   OnePlan                             0x000000010cc65ed8 __50+[MYDynamicObject impForSetterOfProperty:ofClass:]_block_invoke + 43

Christoph Berlin

unread,
Nov 9, 2014, 5:15:07 PM11/9/14
to mobile-c...@googlegroups.com
Ok it seems like we found the root cause (finally). It turns out that something we initialized the wrong database in CBLManager for whatever reason. We don't know why but it happened - however its important to understand that the database was initialized. I still don't understand why this error message would occur but fixing this other more potentially lethal problem fixed this issue as well.

So I guess I answered my own problem but in case anyone ever runs into this issue, have a look at your database object.


On Sunday, November 9, 2014 10:25:09 AM UTC-8, Christoph Berlin wrote:

Traun leyden

unread,
Nov 10, 2014, 10:04:20 AM11/10/14
to mobile-c...@googlegroups.com
Thanks for reporting.  

Can you provide a code sample of triggering the issue?

I'm just wondering if its possible to add a sanity check to CBLModel to detect this and make debugging easier.
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/f51a51f6-c352-4da6-a376-17b50e35fb9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christoph Berlin

unread,
Nov 10, 2014, 12:35:23 PM11/10/14
to mobile-c...@googlegroups.com
Hi Traun,

Its really easy to reproduce once you understand the issue: you call the manager, create a database object but you don’t connect the two…

CBLManager* dbManager = [CBLManager sharedInstance];
CBLDatabase* database;

 Its a really stupid mistake, especially because we should check whether the database actually got created but the error message also threw us off. We were digging around in the model completing missing the fact that there is no database – well there was a database object but unassigned.


Thanks




From: Traun leyden <traun....@gmail.com>
Reply-To: "mobile-c...@googlegroups.com" <mobile-c...@googlegroups.com>
Date: Monday, November 10, 2014 at 7:04 AM
To: "mobile-c...@googlegroups.com" <mobile-c...@googlegroups.com>
Subject: Re: Assertion failure in CBLModel.m:461

Thanks for reporting.  

Can you provide a code sample of triggering the issue?

I'm just wondering if its possible to add a sanity check to CBLModel to detect this and make debugging easier.

On Nov 9, 2014, at 2:15 PM, Christoph Berlin <hoptoawe...@gmail.com> wrote:

Ok it seems like we found the root cause (finally). It turns out that something we initialized the wrong database in CBLManager for whatever reason. We don't know why but it happened - however its important to understand that the database was initialized. I still don't understand why this error message would occur but fixing this other more potentially lethal problem fixed this issue as well.

So I guess I answered my own problem but in case anyone ever runs into this issue, have a look at your database object.

On Sunday, November 9, 2014 10:25:09 AM UTC-8, Christoph Berlin wrote:
Hi,
we are kind of stuck on a problem we cannot explain. Sometimes (not always) we get the following error:

*** Assertion failure in -[OPUserProfile setValue:ofProperty:], /Users/jenkins/jenkins/workspace/build_cblite_ios_102-enterprise/couchbase-lite-ios/Source/API/CBLModel.m:461


Our problem is that the issue occurs randomly - it works about 50% of the time (same functions) while other times it fails. Debugging the issue leads to nowhere.


Does anyone have an idea of what could be the cause?


The OPProfilefunction does nothing fancy but we know that it fails at 


self.user_id = user_id;
 


- (instancetype) initCurrentUserProfileInDatabase: (CBLDatabase*)db andUserID:(NSString*)user_id;

{

    NSParameterAssert(user_id);

    CBLDocument *doc = [db documentWithID:[@"profile:"stringByAppendingString:user_id]];

    self = [superinitWithDocument:doc];

    if (self)

    {

        self.user_id = user_id;

        self.type = kOPDocType_UserProfile;

        self.created_at = [NSDatedate];

    }

    return self;

}


--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/f51a51f6-c352-4da6-a376-17b50e35fb9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/xvJOvcRtQnI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CC2E1449-8D75-4AAE-8E24-1FCBAB8DB985%40gmail.com.

Jens Alfke

unread,
Nov 10, 2014, 1:42:09 PM11/10/14
to mobile-c...@googlegroups.com

> On Nov 10, 2014, at 9:35 AM, Christoph Berlin <ma...@christophberlin.com> wrote:
>
> Its a really stupid mistake, especially because we should check whether the database actually got created but the error message also threw us off.

So your database reference is nil, and presumably when you looked up a document you got nil. But how did you create the model object? +modelForDocument: will immediately trigger an assertion failure if the document is nil, and -initWithNewDocumentInDatabase: also fails if database is nil.

The only way that I can see to create a CBLModel without a document is to call -initWithDocument: nil … but you should never call that yourself. The docs say "Do not call directly except from subclass initializers; to create a new instance call +modelForDocument: instead."

—Jens

Christoph Berlin

unread,
Nov 10, 2014, 5:16:33 PM11/10/14
to mobile-c...@googlegroups.com
Ok I spent some more time on this and I think I found the issue…

As you hinted we DO NOT call -initWithDocument outside the subclass initializers. The issue occurs when trying to call the document initializer itself…see below:

When the database is nil, the initial document is nil as well

CBLDocument *doc = [db documentWithID:[@"profile:" stringByAppendingString:user_id]];


But it doesn’t fail…then when we call initwithDocument and when trying to set the first property It blows up.

Success with properly initialized database:


Failure with database is nil:


As soon as the debugger steps forward we get this error:

2014-11-10 14:11:43.322 OnePlan[30062:712261] *** Assertion failure in -[OPUserProfile setValue:ofProperty:], /Users/jenkins/jenkins/workspace/build_cblite_ios_102-enterprise/couchbase-lite-ios/Source/API/CBLModel.m:461

Jens Alfke

unread,
Nov 10, 2014, 5:31:50 PM11/10/14
to mobile-c...@googlegroups.com
Your code is calling -initWithDocument: with a nil document, which is illegal. That initializer doesn't throw an exception, because there's a valid situation internally where it can be called with nil, but when you do it, the model is left in an illegal state.

I think I should remove -initWithDocument: from the public API  The reason it's there is so you can hook into the initialization and set up your own instance variables, but I can add a new public method to override, to do that in a safer and easier to understand way.

In general, you shouldn't initialize a model object with an -init-type method like your -initCurrentUserProfileInDatabase:. Instead you should call +modelForDocument:. The basic reason is that there can only be one CBLModel instance for a document at a time, and if you could initialize them by calling -initWithDocument:, it would be possible to create two with the same document.

—Jens

Christoph Berlin

unread,
Nov 10, 2014, 5:39:01 PM11/10/14
to mobile-c...@googlegroups.com
I don’t argue with that – I got the idea from the Todo sample code which is shamelessly copied.


Just for my own understanding can you see a fundamental difference between this sample code and what we are doing? I am just curious…again I don’t need to repeat myself that we had a major brain fart when uninitializing the database object and causing the whole blowup but still…

Thanks as always
Christoph 

From: Jens Alfke <je...@couchbase.com>
Reply-To: "mobile-c...@googlegroups.com" <mobile-c...@googlegroups.com>
Date: Monday, November 10, 2014 at 2:31 PM
To: "mobile-c...@googlegroups.com" <mobile-c...@googlegroups.com>
Subject: Re: Assertion failure in CBLModel.m:461

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/xvJOvcRtQnI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Nov 10, 2014, 5:51:17 PM11/10/14
to mobile-c...@googlegroups.com

> On Nov 10, 2014, at 2:38 PM, Christoph Berlin <ma...@christophberlin.com> wrote:
>
> I don’t argue with that – I got the idea from the Todo sample code which is shamelessly copied.

The Profile class in ToDoLite shouldn't be doing it either. Sorry about that.

—Jens

Christoph Berlin

unread,
Nov 10, 2014, 5:52:37 PM11/10/14
to mobile-c...@googlegroups.com
Don¹t worry! It was just for my own education to understand whether we
missed somethingŠwho ever copies in the first place must live with the
consequences :)
>--
>You received this message because you are subscribed to a topic in the
>Google Groups "Couchbase Mobile" group.
>To unsubscribe from this topic, visit
>https://groups.google.com/d/topic/mobile-couchbase/xvJOvcRtQnI/unsubscribe
>.
>To unsubscribe from this group and all its topics, send an email to
>mobile-couchba...@googlegroups.com.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/mobile-couchbase/7DD8FD98-6889-4E66-8A35
>-DADC55E9FC23%40couchbase.com.

Traun Leyden

unread,
Nov 11, 2014, 3:43:00 PM11/11/14
to mobile-c...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/7DD8FD98-6889-4E66-8A35-DADC55E9FC23%40couchbase.com.
Reply all
Reply to author
Forward
0 new messages