FMDatabase is currently in use

592 views
Skip to first unread message

Putra

unread,
Jan 13, 2012, 12:32:15 PM1/13/12
to Mobile Couchbase
Got another problem.

I have one button. If it is pressed, it will generate some records
(documents) in touchDB database.

The problem is that when i press that button, and while it has not
finished generating the records, i then quickly repress or press again
the button, my app generates error:

2012-01-14 00:24:23.130 Imunisasi[9123:707] The FMDatabase
<FMDatabase: 0x270860> is currently in use.
2012-01-14 00:24:23.137 Imunisasi[9123:707] *** Assertion failure in -
[FMDatabase warnInUse], /Users/himawanputra/Documents/Dev/Xcode/
TouchDB-iOS/vendor/fmdb/src/FMDatabase.m:244
2012-01-14 00:24:23.145 Imunisasi[9123:707] *** Terminating app due to
uncaught exception 'NSInternalInconsistencyException', reason: 'The
FMDatabase <FMDatabase: 0x270860> is currently in use.

Regards.

Jens Alfke

unread,
Jan 13, 2012, 12:49:05 PM1/13/12
to mobile-c...@googlegroups.com
On Jan 13, 2012, at 9:32 AM, Putra wrote:

I have one button. If it is pressed, it will generate some records
(documents) in touchDB database.

It sounds like it generates these in the background without blocking the UI, since you can press the button while it’s running. Are you spawning a background thread to create the documents? And what API are you calling on that thread?

(I don’t think this is directly related to your problem, but be aware that CouchCocoa is not thread-safe, meaning that a single CouchCocoa object tree — server, databases, documents, etc. — should only be used on one thread at a time. In other words, create a new CouchServer instance for each thread.)

The problem is that when i press that button, and while it has not
finished generating the records, i then quickly repress or press again
the button, my app generates error:

2012-01-14 00:24:23.130 Imunisasi[9123:707] The FMDatabase
<FMDatabase: 0x270860> is currently in use.

Please post a backtrace. In fact, a full thread dump would be good here. When Xcode drops into the debugger due to the uncaught exception, go to the debugger console view and enter “thread apply all bt”, then copy and paste the output. Since it’s likely to be lengthy, why don’t you file it in a bug report instead of posting it here.

In the meantime, I believe you can work around the problem by avoiding use of a background thread. Instead, perform the operations asynchronously. You can either start them all up at once (NSURLConnection will queue them for you), or start one at a time and, in its completion block, start the next one.

Thanks!

—Jens

Putra

unread,
Jan 13, 2012, 1:09:39 PM1/13/12
to Mobile Couchbase
I don't think i spawn a background thread. I'm using the CouchModel
save method when generating and saving those documents. Using
CouchModel, i couldn't have access to completion block... i would need
to use the non-couchmodel to save the documents.

additional info, i'm also using singleton pattern when i init the
database, like this:

+(DBManager *)singleton {
static dispatch_once_t pred;
static DBManager *shared = nil;

dispatch_once(&pred, ^{
shared = [[DBManager alloc] init];
});
return shared;
}

On Jan 14, 12:49 am, Jens Alfke <j...@couchbase.com> wrote:
> On Jan 13, 2012, at 9:32 AM, Putra wrote:
>
> I have one button. If it is pressed, it will generate some records
> (documents) in touchDB database.
>
> It sounds like it generates these in the background without blocking the UI, since you can press the button while it’s running. Are you spawning a background thread to create the documents? And what API are you calling on that thread?
>
> (I don’t think this is directly related to your problem, but be aware that CouchCocoa is not thread-safe, meaning that a single CouchCocoa object tree — server, databases, documents, etc. — should only be used on one thread at a time. In other words, create a new CouchServer instance for each thread.)
>
> The problem is that when i press that button, and while it has not
> finished generating the records, i then quickly repress or press again
> the button, my app generates error:
>
> 2012-01-14 00:24:23.130 Imunisasi[9123:707] The FMDatabase
> <FMDatabase: 0x270860> is currently in use.
>
> Please post a backtrace. In fact, a full thread dump would be good here. When Xcode drops into the debugger due to the uncaught exception, go to the debugger console view and enter “thread apply all bt”, then copy and paste the output. Since it’s likely to be lengthy, why don’t you file it in a bug report<https://github.com/couchbaselabs/TouchDB-iOS/issues/new> instead of posting it here.

Jens Alfke

unread,
Jan 13, 2012, 8:00:53 PM1/13/12
to mobile-c...@googlegroups.com
OK, interesting. As I said, please get a stack dump and file a bug report. Thanks.

—Jens

Putra

unread,
Jan 13, 2012, 11:17:16 PM1/13/12
to Mobile Couchbase
Ok. Will do the stack dump and file a bug.

Thanks!
Reply all
Reply to author
Forward
0 new messages