Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE FROM @AsyncOpen to @AutoOpen CRASHES #7798

Open
chrisrohrer opened this issue Jun 11, 2024 · 19 comments
Open

CHANGE FROM @AsyncOpen to @AutoOpen CRASHES #7798

chrisrohrer opened this issue Jun 11, 2024 · 19 comments
Assignees
Labels
Needs-Attention Reporter has responded. Review comment. O-Community

Comments

@chrisrohrer
Copy link

SDK and version

SDK : RealmSwift
Version: 10.51.0

Observations

  • How frequent do the crash occur? - ALWAYS
  • Does it happen in production or during dev/test? - DEV BUILD & RUN
  • Can the crash be reproduced by you? - ALWAYS
  • Can you provide instructions for how we can reproduce it? NOT WITHOUT MY FULL CODE

Crash log / stacktrace

/Users/crohrer/Library/Developer/Xcode/DerivedData/PooolRealm-dzsawcsrvibeudciyiphrqrzernr/SourcePackages/checkouts/realm-core/src/realm/exceptions.cpp:80: [realm-core-14.9.0] Unreachable code
0 RealmSwift 0x000000010b1cdb14 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1 RealmSwift 0x000000010b1cdaf4 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 308
2 RealmSwift 0x000000010b1cd9c0 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0
3 RealmSwift 0x000000010aa32f58 _ZN5realm19exception_to_statusEv + 304
4 RealmSwift 0x000000010ad2b93c _ZN5realm13AsyncOpenTask34attach_to_subscription_initializerEONS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEEb + 224
5 RealmSwift 0x000000010ad2c528 _ZN5realm13AsyncOpenTask30wait_for_bootstrap_or_completeEONS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEENS_6StatusE + 256
6 RealmSwift 0x000000010ad2c1ec _ZN5realm13AsyncOpenTask26migrate_schema_or_completeEONS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEENS_6StatusE + 236
7 RealmSwift 0x000000010ad2d4e8 _ZZN5realm13AsyncOpenTask5startENS_4util14UniqueFunctionIFvNS_19ThreadSafeReferenceESt13exception_ptrEEEEN3$_0clENS_6StatusE + 396
8 RealmSwift 0x000000010ad2d214 _ZN5realm4util14UniqueFunctionIFvNS_6StatusEEE12SpecificImplIZNS_13AsyncOpenTask5startENS1_IFvNS_19ThreadSafeReferenceESt13exception_ptrEEEE3$0E4callEOS2 + 60
9 RealmSwift 0x000000010ad65944 ZNK5realm4util14UniqueFunctionIFvNS_6StatusEEEclES2 + 112
10 RealmSwift 0x000000010ad86314 _ZZN5realm11SyncSession23add_completion_callbackENS_4util14UniqueFunctionIFvNS_6StatusEEEENS_5_impl20SyncProgressNotifier12NotifierTypeEENK3$0clES3 + 224
11 RealmSwift 0x000000010ad86174 _ZN5realm4util14UniqueFunctionIFvNS_6StatusEEE12SpecificImplIZNS_11SyncSession23add_completion_callbackES4_NS_5_impl20SyncProgressNotifier12NotifierTypeEE3$0E4callEOS2 + 60
12 RealmSwift 0x000000010ad65944 ZNK5realm4util14UniqueFunctionIFvNS_6StatusEEEclES2 + 112
13 RealmSwift 0x000000010af31284 _ZN5realm4sync14SessionWrapper22on_download_completionEv + 112
14 RealmSwift 0x000000010af31204 _ZN5realm4sync10ClientImpl7Session22on_download_completionEv + 56
15 RealmSwift 0x000000010b017a64 _ZN5realm4sync10ClientImpl7Session29check_for_download_completionEv + 304
16 RealmSwift 0x000000010b01550c _ZN5realm4sync10ClientImpl7Session20receive_mark_messageEy + 416
17 RealmSwift 0x000000010b0152f0 _ZN5realm4sync10ClientImpl10Connection20receive_mark_messageEyy + 124
18 RealmSwift 0x000000010b01232c _ZN5realm5_impl14ClientProtocol22parse_message_receivedINS_4sync10ClientImpl10ConnectionEEEvRT_NSt3__117basic_string_viewIcNS8_11char_traitsIcEEEE + 4444
19 RealmSwift 0x000000010b00deb4 _ZN5realm4sync10ClientImpl10Connection23handle_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 112
20 RealmSwift 0x000000010b00dd9c _ZN5realm4sync10ClientImpl10Connection33websocket_binary_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 252
21 RealmSwift 0x000000010b026e24 _ZN5realm4sync10ClientImpl10Connection21WebSocketObserverShim33websocket_binary_message_receivedENS_4util4SpanIKcLm18446744073709551615EEE + 100
22 RealmSwift 0x000000010af86f20 _ZN5realm4sync9websocket12_GLOBAL__N_120DefaultWebSocketImpl33websocket_binary_message_receivedEPKcm + 80
23 RealmSwift 0x000000010afbfbe8 _ZN12_GLOBAL__N_19WebSocket17frame_reader_loopEv + 232
24 RealmSwift 0x000000010afc16a4 _ZZN12_GLOBAL__N_19WebSocket17frame_reader_loopEvENKUlNSt3__110error_codeEmE_clES2_m + 176
25 RealmSwift 0x000000010afc15bc _ZN5realm4util14UniqueFunctionIFvNSt3__110error_codeEmEE12SpecificImplIZN12_GLOBAL__N_19WebSocket17frame_reader_loopEvEUlS3_mE_E4callEOS3_Om + 64
26 RealmSwift 0x000000010af99f78 _ZNK5realm4util14UniqueFunctionIFvNSt3__110error_codeEmEEclES3_m + 120
27 RealmSwift 0x000000010af99cec ZN5realm4sync7network7Service9AsyncOper29do_recycle_and_execute_helperINS_4util14UniqueFunctionIFvNSt3__110error_codeEmEEEJS8_mEEEvbRbT_DpT0 + 116
28 RealmSwift 0x000000010af99bfc ZN5realm4sync7network7Service9AsyncOper22do_recycle_and_executeINS_4util14UniqueFunctionIFvNSt3__110error_codeEmEEEJRS8_RmEEEvbRT_DpOT0 + 168
29 RealmSwift 0x000000010af9964c _ZN5realm4sync7network7Service14BasicStreamOpsINS1_3ssl6StreamEE16BufferedReadOperINS_4util14UniqueFunctionIFvNSt3__110error_codeEmEEEE19recycle_and_executeEv + 656
30 RealmSwift 0x000000010afab448 _ZN5realm4sync7network7Service4Impl7executeERNSt3__110unique_ptrINS2_9AsyncOperENS2_18LendersOperDeleterEEE + 36
31 RealmSwift 0x000000010afab154 _ZN5realm4sync7network7Service4Impl8run_implEb + 316
32 RealmSwift 0x000000010afa6f08 _ZN5realm4sync7network7Service4Impl17run_until_stoppedEv + 32
33 RealmSwift 0x000000010afa6edc _ZN5realm4sync7network7Service17run_until_stoppedEv + 28
34 RealmSwift 0x000000010af80474 _ZN5realm4sync9websocket21DefaultSocketProvider10event_loopEv + 352
35 RealmSwift 0x000000010af84c00 ZNSt3__18__invokeB8de180100IMN5realm4sync9websocket21DefaultSocketProviderEFvvEPS4_JEvEEDTcldsdeclsr3stdE7declvalIT0_EEclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT1_EEEEOS9_OS8_DpOSA + 132
36 RealmSwift 0x000000010af84b70 _ZNSt3__116__thread_executeB8de180100INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEMN5realm4sync9websocket21DefaultSocketProviderEFvvEJPS9_EJLm2EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE + 48
37 RealmSwift 0x000000010af8481c ZNSt3__114__thread_proxyB8de180100INS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN5realm4sync9websocket21DefaultSocketProviderEFvvEPSA_EEEEEPvSF + 84
38 libsystem_pthread.dylib 0x00000001031529ac _pthread_start + 136
39 libsystem_pthread.dylib 0x000000010315ccfc thread_start + 8

Steps & Code to Reproduce

CHANGED FROM @AsyncOpen to @AutOOpeN

Copy link

sync-by-unito bot commented Jun 11, 2024

➤ PM Bot commented:

Jira ticket: RCORE-2163

@ironage
Copy link
Contributor

ironage commented Jun 11, 2024

Hi @chrisrohrer, are you able to set an "c++ exception breakpoint" in debug mode so that we can see what is being thrown?
The unreachable code is due to exception_to_status() not being able to convert from a standard exception type.

Status exception_to_status() noexcept
{
    try {
        throw;
    }
    catch (const Exception& e) {
        return e.to_status();
    }
    catch (const std::exception& e) {
        return Status(ErrorCodes::UnknownError,
                      util::format("Caught std::exception of type %1: %2", util::get_type_name(e), e.what()));
    }
    catch (...) {
        REALM_UNREACHABLE();
    }
}

@chrisrohrer
Copy link
Author

chrisrohrer commented Jun 11, 2024 via email

@chrisrohrer
Copy link
Author

chrisrohrer commented Jun 11, 2024 via email

@ironage
Copy link
Contributor

ironage commented Jun 11, 2024

@chrisrohrer thanks for that!
Could you provide the stack trace of that exception please? I'd expect it should have attach_to_subscription_initializer in it somewhere.

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Jun 11, 2024
@chrisrohrer
Copy link
Author

chrisrohrer commented Jun 12, 2024 via email

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Jun 12, 2024
@ironage
Copy link
Contributor

ironage commented Jun 12, 2024

@chrisrohrer thanks, a screenshot should work. But I am unable to view your image when you reply by email. Are you able to go to the github issue and add the attachment directly in a comment there?

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Jun 12, 2024
@chrisrohrer
Copy link
Author

Unknown

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Jun 12, 2024
@ironage
Copy link
Contributor

ironage commented Jun 12, 2024

Thanks @chrisrohrer that is good information. The exception is from ObjectiveC which is why our conversion handlers don't recognize it.
Do you have a configuration.schemaVersion set? As of 10.46.0 you must set it to zero for sync'd Realms (see changelog).

@chrisrohrer
Copy link
Author

thanks for taking all this time to look into this!
and thanks for the hint to set configuration.schemaVersion, just included that.

Actually I downgraded from macOS 15 beta back to 14.5 (and Xcode 15.4) because of the issue.
It's much better now, but most interestingly the crash does still occur from time to time (never did before the initial upgrade)

I just found out that changing rerunOnOpen: in user.flexibleSyncConfiguration() from TRUE to FALSE seems to fix it.
I strongly guess it is a timing issue in loading the subscriptions ...

Bildschirmfoto 2024-06-12 um 21 46 38

@nirinchev
Copy link
Member

Can you share the code for your models? These schema validation errors are surprising and I'm hoping there's something in your models that could point us in the right direction.

@chrisrohrer
Copy link
Author

Specific models or all of them? It has around 40 model classes ...

@chrisrohrer
Copy link
Author

I get this from time to time
Bildschirmfoto 2024-06-13 um 19 05 16

@chrisrohrer
Copy link
Author

chrisrohrer commented Jun 13, 2024

OK, I did have an incorrect one to many relationship definition:

class Budget: Object, ObjectKeyIdentifiable {

    @Persisted(primaryKey: true) var _id: ObjectId
    
    @Persisted var name: String = ""
    @Persisted var verantwortlich: String = ""
    @Persisted var zielwert: Double
    @Persisted var jahr: Int = Date.now.year()

    @Persisted var kategorie: BudgetKategorie?

    @Persisted(originProperty: "budget") var positionen: LinkingObjects<Position>


class BudgetKategorie: Object, ObjectKeyIdentifiable {

    @Persisted(primaryKey: true) var _id: ObjectId
    
    @Persisted var name: String = ""
    
//    @Persisted var budgets: List<Budget> // old Version: WRONG !!
    @Persisted(originProperty: "kategorie") var budgets: LinkingObjects<Budget>


Lets see if that fixes it ...

@nirinchev
Copy link
Member

I don't know if we need all of them, but at least those that are mentioned in the error message - for example it states that Position.budget doesn't exist which is why the linking objects property Budget.positionen is invalid.

@chrisrohrer
Copy link
Author

all those error messages don't make sense, as the program and database work in 90% of the time.
The error appears only sometimes when I build & run while the program is still running.

My guess is the schema is not yet fully loaded when it s checked internally - or some issue with concurrency?
Or can it be an issue with the order of subscription checking??

@ironage
Copy link
Contributor

ironage commented Jun 17, 2024

I think this may have been fixed by #7723 @danieltabacaru do you think so?

@chrisrohrer if you are able to, could you try to reproduce this with core v14.10.1? (the realm-swift SDK has not picked this up yet, but should do so in the next week or so)

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Jun 17, 2024
@danieltabacaru
Copy link
Collaborator

@ironage I am not sure if my change is going to make a difference, but it's worth trying. I find it odd that setting rerunOnOpen to false fixes the issue, when it's the schema validation in update_schema that seems to cause the issue.

@chrisrohrer Are you changing the schema between runs? Is it a fresh realm the app uses? Are you using developer mode? At the point of the crash the schema should already be downloaded from the server, and if it matches the client one, then there should be no schema validation (unless you use developer mode or make additive changes to the schema).

@chrisrohrer
Copy link
Author

@danieltabacaru I am actually using developer mode!
Since I downgraded back to macOS 14.5 and Xcode 15.4 and using rerunOnOpen: false the error has not appeared again. So I guess we can close for now and I'll check on macOS 15 at a later stage.

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Attention Reporter has responded. Review comment. O-Community
Projects
None yet
Development

No branches or pull requests

4 participants