Database error android touchDB

150 views
Skip to first unread message

bugg l'eclair

unread,
Aug 13, 2012, 12:41:15 PM8/13/12
to mobile-c...@googlegroups.com
Hey guys,

is anyone has already have this following error?

08-13 18:33:39.501: E/Database(790): close() was never explicitly called on database '/data/data/org.cozyAndroid/files/grocery-sync.touchdb'
08-13 18:33:39.501: E/Database(790): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
08-13 18:33:39.501: E/Database(790):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
08-13 18:33:39.501: E/Database(790):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
08-13 18:33:39.501: E/Database(790):     at com.couchbase.touchdb.TDDatabase.open(TDDatabase.java:233)
08-13 18:33:39.501: E/Database(790):     at com.couchbase.touchdb.TDView.setMapReduceBlocks(TDView.java:141)
08-13 18:33:39.501: E/Database(790):     at org.cozyAndroid.Replication.NotesView(Replication.java:70)
08-13 18:33:39.501: E/Database(790):     at org.cozyAndroid.TabListe.onCreate(TabListe.java:51)
 
As you can see, the error comes from the NotesView function and trigger some errors in touchDB's classes.

Here is my NotesView function:

String filesDir = context.getFilesDir().getAbsolutePath();
        try {
            server = new TDServer(filesDir);
        } catch (IOException e) {
            Log.e(TAG, "Error starting TDServer", e);
        }

        //install a view definition needed by the application
        TDDatabase db = server.getDatabaseNamed(DATABASE_NOTES);
        TDView view = db.getViewNamed(String.format("%s/%s", dDocName, byDateViewName));
        view.setMapReduceBlocks(new TDViewMapBlock() {

            @Override
            public void map(Map<String, Object> document, TDViewMapEmitBlock emitter) {
                Object modifiedAt = document.get("modified_at");
                Object type = document.get("type");
                if( (type == null || type.toString().equals("note")) && modifiedAt != null) {
                    emitter.emit(modifiedAt.toString(), document);
                }
            }
        }, null, "1.0");

The line 70 fit with "view.setMapReduceBlocks( ...)  { "

What am I doing wrong?

Thanks in advance ;)

Marty Schoch

unread,
Aug 13, 2012, 12:46:18 PM8/13/12
to mobile-c...@googlegroups.com
Does your app ever call server.close()? That is the most common cause
of this error.

marty

bugg l'eclair

unread,
Aug 14, 2012, 4:20:14 AM8/14/12
to mobile-c...@googlegroups.com
I'm pretty sure i never call server.close. But I'm basing on the android Grocery app and this is never called in it.
Where do i have to call it? Because I want a permanent replication and i cannot do it if i close the server, am i right?

Thanks

bugg l'eclair

unread,
Aug 14, 2012, 4:21:48 AM8/14/12
to mobile-c...@googlegroups.com
And it's weird because this error is not frequent, so if it is a problem of server not closed, why this error is not raised at any time?

bugg l'eclair

unread,
Aug 14, 2012, 5:26:27 AM8/14/12
to mobile-c...@googlegroups.com
I've tried to put server.close() in the onDestroy() of the application and i get this log:

08-14 11:24:52.511: E/ContinuousChangesFeed(1367): Caught exception while listening to changes feed:
08-14 11:24:52.511: E/ContinuousChangesFeed(1367): java.io.IOException: Pipe broken
08-14 11:24:52.511: E/ContinuousChangesFeed(1367):     at java.io.PipedInputStream.read(PipedInputStream.java:328)
08-14 11:24:52.511: E/ContinuousChangesFeed(1367):     at java.io.InputStreamReader.read(InputStreamReader.java:275)
08-14 11:24:52.511: E/ContinuousChangesFeed(1367):     at java.io.BufferedReader.fillBuf(BufferedReader.java:155)
08-14 11:24:52.511: E/ContinuousChangesFeed(1367):     at java.io.BufferedReader.readLine(BufferedReader.java:386)
08-14 11:24:52.511: E/ContinuousChangesFeed(1367):     at org.ektorp.impl.changes.ContinuousChangesFeed.run(ContinuousChangesFeed.java:113)
08-14 11:24:52.511: E/ContinuousChangesFeed(1367):     at java.lang.Thread.run(Thread.java:1096)
08-14 11:24:52.561: E/ContinuousChangesFeed(1367): Caught exception while listening to changes feed:
08-14 11:24:52.561: E/ContinuousChangesFeed(1367): java.io.IOException: Pipe broken
08-14 11:24:52.561: E/ContinuousChangesFeed(1367):     at java.io.PipedInputStream.read(PipedInputStream.java:328)
08-14 11:24:52.561: E/ContinuousChangesFeed(1367):     at java.io.InputStreamReader.read(InputStreamReader.java:275)
08-14 11:24:52.561: E/ContinuousChangesFeed(1367):     at java.io.BufferedReader.fillBuf(BufferedReader.java:155)
08-14 11:24:52.561: E/ContinuousChangesFeed(1367):     at java.io.BufferedReader.readLine(BufferedReader.java:386)
08-14 11:24:52.561: E/ContinuousChangesFeed(1367):     at org.ektorp.impl.changes.ContinuousChangesFeed.run(ContinuousChangesFeed.java:113)
08-14 11:24:52.561: E/ContinuousChangesFeed(1367):     at java.lang.Thread.run(Thread.java:1096)

Marty Schoch

unread,
Aug 14, 2012, 10:17:44 AM8/14/12
to mobile-c...@googlegroups.com
On Tue, Aug 14, 2012 at 4:20 AM, bugg l'eclair <jeremy...@gmail.com> wrote:
> I'm pretty sure i never call server.close. But I'm basing on the android
> Grocery app and this is never called in it.
> Where do i have to call it? Because I want a permanent replication and i
> cannot do it if i close the server, am i right?

This error occurs when finalize() occurs on either a Cursor or
Database object that was not closed cleanly. I don't think its a
Cursor in this case, as when we leak these I usually see them in the
unit tests. Databases are different though because as long as you
have a TDDatabase object alive, you intended to keep the SQLiteDatbase
open as well.

The issue can arise when you open a TDDatabase (say in your
applications main Activity) but then never close it. Typically this
would be done because you want to keep replications running in the
background. But, the OS can decide to shutdown or kill your app at a
later time. Depending on how this happens, you may see the message
show up in the logs at that time.

Generally this message is not a problem, other than warning that you
may be leaking the object. If your goal is to keep replications
running in the background I'm not sure how we can avoid this.

marty

Marty Schoch

unread,
Aug 14, 2012, 10:19:12 AM8/14/12
to mobile-c...@googlegroups.com
On Tue, Aug 14, 2012 at 4:21 AM, bugg l'eclair <jeremy...@gmail.com> wrote:
> And it's weird because this error is not frequent, so if it is a problem of
> server not closed, why this error is not raised at any time?

The message happens when the VM garbage collects the object you
created the TDDatabse object in. So if you opened it in the activty
and kept the reference there. You won't get it when activity is taken
off screen, you'll get it when the VM decides to clean it up, which
you have no control over. This is why you may see it at odd times (or
not at all in some cases)

marty

Marty Schoch

unread,
Aug 14, 2012, 10:21:33 AM8/14/12
to mobile-c...@googlegroups.com
I see this a lot. I'm not sure if we can shut the changes feeds down
cleaner and avoid this, or if its just the way Ektorp handles it. You
can log a bug for this if you want, but its low priority as it doesn't
really cause any harm.

marty

bugg l'eclair

unread,
Aug 14, 2012, 12:36:41 PM8/14/12
to mobile-c...@googlegroups.com
Yes I undertand it's not a priority. Good luck for other things, really thank you for the answer and i'll go back to this later.
Reply all
Reply to author
Forward
0 new messages