Anonymous login works only once, after re-running the app it crashes

I’m working on an app for iOS. I was using email/password auth so far, but wanted to let user to get started with the app before registering with help of anonymous auth. In the first run of the app everything seemed to be working fine, but after running it for the second time it throws “Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)” at the line with DispatchQueue.main.sync. The code is very simple and based on the example from tutorials, so I wonder if that’s a fault with the MongoDB Realm itself? Here is the code:

func loginAnon() {
    let anonymousCredentials = Credentials.anonymous()
    realmApp.login(credentials: anonymousCredentials) { (user, error) in
        DispatchQueue.main.sync {
            guard error == nil else {
                print("Login failed: \(error!)")
                return
            }
            
            Realm.asyncOpen(configuration: user!.configuration(partitionValue: user!.id!)) { [weak self](realm, error) in
                guard let realm = realm else {
                    fatalError("Failed to open realm: \(error!.localizedDescription)")
                }

                // This simply passes realm instance to next view controller and loads next view controller
                self!.delegate?.loginAnonDidComplete(self!, realm: realm)
            }
        }
    }
}

I’ve noticed another thing. I can run this code fine, but only once on each MacBook.

Seems like a bug in the Cocoa SDK - can you file an issue and we’ll have an engineer take a look.

We’re seeing the exact same error with 10.0.0-beta.6. It was working with beta.4. I filed an issue.