realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Internal crash on OsJavaNetworkTransport.cpp #7864

Open jhonnyinstacart opened 5 months ago

jhonnyinstacart commented 5 months ago

How frequently does the bug occur?

Sometimes

Description

Sometimes when we try to access a realm it crashes our app, don´t really have much info per the stacktrace but hopefully it means something for you guys, our QA team says it happens from time to time.

Stacktrace & log output

Fatal Exception: java.lang.IllegalArgumentException: Illegal Argument: Invalid column key in /tmp/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_objectstore_OsJavaNetworkTransport.cpp line 61
       at io.realm.internal.objectstore.OsJavaNetworkTransport.nativeHandleResponse(OsJavaNetworkTransport.java)
       at io.realm.internal.objectstore.OsJavaNetworkTransport.handleResponse(OsJavaNetworkTransport.java:98)
       at io.realm.internal.network.OkHttpNetworkTransport$1.run(OkHttpNetworkTransport.java:102)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)

Can you reproduce the bug?

Sometimes

Reproduction Steps

No response

Version

10.17.0

What Atlas App Services are you using?

Atlas Device Sync

Are you using encryption?

No

Platform OS and version(s)

Android 10

Build environment

Android Studio version: Android Studio Hedgehog | 2023.1.1 Canary 15 Android Build Tools version: 33.0.2 Gradle version: 7.6.2

cmelchior commented 4 months ago

Hmm, the crash is associated with HTTP requests going to App Services. The error message "Invalid column key" however is an internal crash saying that our association between model class properties and their underlying representation is no longer correct.

This is a bit weird, since Device Sync does not use the OsJavaNetworkTransport class, it uses its own Websocket connection.

Are you by any chance using Functions? And if yes, are you perhaps writing to the Realm using the result of the function response?

jhonnyinstacart commented 4 months ago

mmm no I don't think so @cmelchior, we don't write at any time on our app, writes are even set to false on our device sync config, only reads are allowed, all writes are done by the sync SDK internally while syncing.

rorbech commented 4 months ago

Hi @jhonnyinstacart. Could this somehow be related to testing scenarios of upgrading or downgrading the application? The user metadata is stored in an internal realm-file. The schema of this realm changed with 10.17.0, so ex. downgrading from that version to a prior one would require the user to login again, and some scenarios with user/authentication operations could maybe trigger the above error. Can you try to elaborate on the use cases that triggers this?

jhonnyinstacart commented 4 months ago

I think you might be right @rorbech, thanks for the suggestion, we are still trying to come up with repro steps, no luck just yet, but independently can you guys make a fix for this based on your theory? the SDK should def not crash when upgrading or downgrading 🙏

rorbech commented 4 months ago

Hi @jhonnyinstacart. I have tried replicating your issue by updating and downgrading across 10.16.2 and 10.17.0. Upgrading works, but downgrading is not possible because of an internal check in core that does not work as intended (https://github.com/realm/realm-core/pull/7256). The work around for downgrading would be to delete the metadata Realm in $[SYNC-ROOT-DIRECTORY]/mongodb-realm/[APP-ID]/server-utility/metadata/ as part of the downgrade and would of course require logging in again.

Even with the very unfortunate issue of not being able to downgrade, I cannot provoke you crash, so please gather information on any use case leading up to the crash.