Closed K-Leon closed 5 years ago
@K-Leon Of course I'll look into it!
Can you get me a bit more of the log context? This one doesn't even say what happened!
Also, as close as you can get to steps to replicate would help a lot.
I'm updating from 2.5.3 to 2.6.0 and I get this crash when I select the fields property in the data. So it might have something to do with that. If I remove the "fields" column from the select it will work fine.
Data Example:
{
"cells": {},
"channels": [
...
],
"createdAt": "2019-09-12T14:09:00.859Z",
"createdByIP": "###.###.###.###",
"creator": "user::test@example.com",
"fields": [
{
"fieldType": "textField",
"index": 0,
"name": "Title",
"textField": {}
}
],
"groupID": "group::test@example.com",
"name": "Test 1",
"organizationID": "organization::test@example.com",
"sharedUsers": [
...
],
"type": "sheet",
"updatedAt": "2019-09-26T19:09:22.813Z",
"updatedByIP": "###.###.###.###"
}
Live Query Example:
final Query query = QueryBuilder.select(
SelectResult.expression(Expression.property("name").from("sheets")),
SelectResult.expression(Expression.property("fields").from("sheets")),
SelectResult.expression(Expression.property("createdAt").from("sheets")),
SelectResult.expression(Expression.property("updatedAt").from("sheets")),
SelectResult.expression(Expression.property("deletedAt").from("sheets"))
)
.from(DataSource.database(myDatabase).as("sheets"))
.where(Meta.id.from("sheets").equalTo(Expression.string(documentID)));
Error Output
F/libc ( 5166): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 5198 (AsyncTask #1)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/zeroflteue/zerofltetmo:7.0/NRD90M/G920TUES6ERC2:user/release-keys'
Revision: '11'
ABI: 'arm64'
pid: 5166, tid: 5198, name: AsyncTask #1 >>> com.example.android.dev <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
x0 0000000000000000 x1 00000073da748bd4 x2 00000073932493c0 x3 00000073dbc70c00
x4 00000073da749068 x5 00000073bd70cb80 x6 00000073bd92251c x7 0000000000000000
x8 6c5544bdb9436207 x9 0000000000000000 x10 0000000000430000 x11 00000073db6b0f7c
x12 00000073db6b0fd0 x13 00000073db6b1024 x14 00000073db6b1084 x15 0000000000000000
x16 0000007376938958 x17 00000073767ae708 x18 0000000070fe0d5c x19 00000073da74c4e8
x20 00000073932493c0 x21 00000073dbc70c00 x22 00000073da748e7c x23 00000073bd70cb80
x24 0000000000000008 x25 6c5544bdb9436207 x26 00000073dbc70c98 x27 6c5544bdb9436207
x28 0000000000000002 x29 00000073da748b30 x30 0000007376796698
sp 00000073da748b00 pc 00000073767ae724 pstate 0000000020000000
backtrace:
#00 pc 000000000031d724 /data/app/com.example.android.dev-1/lib/arm64/libLiteCoreJNI.so (_ZNK6fleece4impl5Value8asStringEv+28)
#01 pc 0000000000305694 /data/app/com.example.android.dev-1/lib/arm64/libLiteCoreJNI.so (_ZNK6fleece4impl4Dict8iterator9keyStringEv+20)
#02 pc 00000000002ff0e8 /data/app/com.example.android.dev-1/lib/arm64/libLiteCoreJNI.so (FLDictIterator_GetKeyString+28)
#03 pc 000000000012a5a0 /data/app/com.example.android.dev-1/lib/arm64/libLiteCoreJNI.so (Java_com_couchbase_lite_internal_fleece_FLDictIterator_getKeyString+20)
#04 pc 00000000007bcc64 /data/app/com.example.android.dev-1/oat/arm64/base.odex (offset 0x784000)
One more thing, @bawelter . I'd like to see the code that you used to build your document
I cannot reproduce this problem. I'm using 2.6.0 and I have code that creates, I believe, exactly that document, and then retrieves it with exactly that query, all with failing. Happy to share it with you, if that is any kind of help.
If you can share your code with me I will find a way to reproduce the error and let you know so you don’t have to waste time.
Right now I’m using flutter so this is all generated through a platform channel, so I just have to rewrite it for android.
Another thing to consider is that there was a query change listener on this as well, which could be the root of the problem.
The only other thing to consider is that the queries are ran on a background thread but I don’t think that is the issue since it works on all other queries.
I will try not putting the listener on and see what I get.
The error is happening in the result.toMap() function.
final Query query = QueryBuilder.select(SelectResult.property("fields"))
.from(DataSource.database(db))
.where(Meta.id.equalTo(Expression.string("sheet-test")));
String snackbarText = "Failed";
try {
ResultSet results = query.execute();
for (Result result : results.allResults()) {
result.toMap();
//Log.d("CouchbaseResults", result.toMap().toString());
}
snackbarText = "Result Count: " + results.allResults().size();
} catch(CouchbaseLiteException e) {
Log.e("CouchbaseTest", e.getLocalizedMessage());
e.printStackTrace();
}
So I tested all scenarios and this always happens with empty javascript objects like below.
{
"myObject" : {}
}
Here is a test case that can be added to couchbase-lite-java/src/shared/test/java/com/couchbase/lite/ResultTest.java
@Test
public void testResultToMap() throws Exception {
String docID = String.format(Locale.ENGLISH, "doc%d", 3);
MutableDocument mDoc = new MutableDocument(docID);
mDoc.setDictionary("emptyDict", new MutableDictionary());
save(mDoc);
final Query query = QueryBuilder.select(
SelectResult.property("emptyDict")
)
.from(DataSource.database(db))
.where(Meta.id.equalTo(Expression.string(docID)));
try {
ResultSet results = query.execute();
for (Result result : results.allResults()) {
result.toMap();
}
} catch(Exception e) {
fail();
}
}
Purposed quick fix is to use the getValue function in the toList() function in /couchbase-lite-java/src/shared/main/java/com/couchbase/lite/Result.java
/**
* Gets all values as an List. The value types of the values contained
* in the returned List object are Array, Blob, Dictionary, Number types, String, and null.
*
* @return The List representing all values.
*/
@NonNull
@Override
public List<Object> toList() {
final List<Object> array = new ArrayList<>();
for (int i = 0; i < count(); i++) {
array.add(getValue(i));
}
return array;
}
I think this is actually a bug in the Native code though not the java code. I will look into this a bit more.
Nice work, @bawelter . On it.
I see you already found this bug, just need to rewrite some loops as @snej just commented a few days ago. Thanks @bmeike !
Tracking affect on Android, here: https://issues.couchbase.com/browse/CBL-436
Thanks for your fix! Is a Backport / Patch Release for 2.6 planned? (e.g. 2.6.0.1)
I can't comment at this point. If you can confirm that this change fixes the problem, it would help.
Is there already a branch or a fixed commit for 2.7 including this fix? I would then start testing it with my app. As i read in other issues it already settelt a bit?
The issue was fixed with the changes you made from what I could tell.
Excellent. Closing. @K-Leon : the fix is on master and you are right not to use master in production. From what I hear, the chances of a 2.6.x patch release are pretty good. Closing
First of Thanks for your hard work!! I just stumbled over a NDK Crash while installing 2.6 over an 2.1.5 Database.
May you look into it? (Taking self build 2.6 or stock 2.6 won't making any difference. Except I can symbolicate the crash dump )
Edit: Upgrading to 2.5.x works. The bug has been introduced lately i guess.