// Ensure the current user exists
guard let user = app.currentUser else {
print("No logged-in user found.")
throw NSError(domain: "Login Error", code: 401, userInfo: [NSLocalizedDescriptionKey: "No logged-in user found."])
}
print("Current user: \(user)")
let config = user.flexibleSyncConfiguration()
print("Flexible sync configuration created.")
// Open Realm asynchronously
let realm = try await Realm(configuration: config)
print("Realm opened successfully.")
// Safely unwrap the email property outside of the subscription update block
guard let userEmail = user.profile.email else {
print("User profile email not found.")
throw NSError(domain: "Profile Error", code: 402, userInfo: [NSLocalizedDescriptionKey: "User profile email not found."])
}
print("User email: \(userEmail)")
// Update subscriptions without removal to avoid potential issues
try await realm.subscriptions.update {
print("Updating subscriptions...")
// Check if a subscription for UserProfile already exists
if let existingSubscription = realm.subscriptions.first(named: "UserProfile") {
print("Existing subscription for UserProfile found.")
} else {
print("No existing subscription found for UserProfile. Adding new subscription for user: \(userEmail)")
// Add a new subscription for the UserProfile filtered by email
realm.subscriptions.append(QuerySubscription<UserProfile>(name: "UserProfile") {
$0.email == userEmail
})
}
}
print("Subscriptions updated successfully.")
// Return the Realm instance after the subscriptions are updated
return realm
SDK and version
SDK : ? (Cocoa, Java, etc) Swift Version: ? Last Version
Observations
Crash log / stacktrace
/Users/mac/Library/Developer/Xcode/DerivedData/chessbrk-fbjogatoybvdkibovkkgafrsticz/SourcePackages/checkouts/realm-core/src/realm/sync/noinst/client_impl_base.hpp:1340: [realm-core-14.12.1] Assertion failed: m_error_message_received || !m_unbind_message_sent 0 RealmSwift 0x000000010c8fbed4 _ZN5realm4utilL18terminate_internalERNSt3118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 56 1 RealmSwift 0x000000010c8fbe98 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 352 2 RealmSwift 0x000000010c8fbd38 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0 3 RealmSwift 0x000000010c61efb8 _ZN5realm4sync10ClientImpl7Session40request_download_completion_notificationEv + 316 4 RealmSwift 0x000000010c61ee28 _ZZN5realm4sync14SessionWrapper14async_wait_forEbbNS_4util14UniqueFunctionIFvNS_6StatusEEEEEN4$10clES4 + 684 5 RealmSwift 0x000000010c61eaa8 _ZN5realm4util14UniqueFunctionIFvNS_6StatusEEE12SpecificImplIZNS_4sync14SessionWrapper14async_wait_forEbbS4_E4$10E4callEOS2 + 96 6 RealmSwift 0x000000010c3c487c _ZNK5realm4util14UniqueFunctionIFvNS6StatusEEEclES2 + 156 7 RealmSwift 0x000000010c724c68 _ZZN5realm4sync10ClientImpl4postEONS_4util14UniqueFunctionIFvNS_6StatusEEEEENK3$1clES4 + 96 8 RealmSwift 0x000000010c724b48 _ZN5realm4util14UniqueFunctionIFvNS_6StatusEEE12SpecificImplIZNS_4sync10ClientImpl4postEOS4_E3$1E4callEOS2 + 96 9 RealmSwift 0x000000010c3c487c _ZNK5realm4util14UniqueFunctionIFvNS6StatusEEEclES2 + 156 10 RealmSwift 0x000000010c65dc78 _ZN5realm4sync7network7Service8PostOperINS_4util14UniqueFunctionIFvNS_6StatusEEEEE19recycle_and_executeEv + 88 11 RealmSwift 0x000000010c69154c _ZN5realm4sync7network7Service4Impl7executeERNSt3110unique_ptrINS2_9AsyncOperENS2_18LendersOperDeleterEEE + 52 12 RealmSwift 0x000000010c6910e0 _ZN5realm4sync7network7Service4Impl8run_implEb + 484 13 RealmSwift 0x000000010c68bc38 _ZN5realm4sync7network7Service4Impl17run_until_stoppedEv + 48 14 RealmSwift 0x000000010c68bbfc _ZN5realm4sync7network7Service17run_until_stoppedEv + 44 15 RealmSwift 0x000000010c65d158 _ZN5realm4sync9websocket21DefaultSocketProvider10event_loopEv + 464 16 RealmSwift 0x000000010c66285c _ZNSt318invokeB8ue170006IMN5realm4sync9websocket21DefaultSocketProviderEFvvEPS4_JEvEEDTcldsdeclsr3stdE7declvalIT0_EEclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT1_EEEEOS9_OS8DpOSA + 132 17 RealmSwift 0x000000010c6627cc _ZNSt3116thread_executeB8ue170006INS_10unique_ptrINS_15thread_structENS_14default_deleteIS2_EEEEMN5realm4sync9websocket21DefaultSocketProviderEFvvEJPS9_EJLm2EEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15tuple_indicesIJXspT2_EEEE + 64 18 RealmSwift 0x000000010c6623b8 _ZNSt3114thread_proxyB8ue170006INS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN5realm4sync9websocket21DefaultSocketProviderEFvvEPSAEEEEEPvSF + 100 19 libsystem_pthread.dylib 0x00000001045d3414 _pthread_start + 104 20 libsystem_pthread.dylib 0x00000001045ce5e0 thread_start + 8 !!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
Steps & Code to Reproduce
func configureFlexibleSync() async throws -> Realm { print("Starting configureFlexibleSync function...")
}