realm-swift: 10.49.1 failing to connect to Atlas Device Sync

Description

I’m using MongoDB Atlas with Device Sync. The bug appear after upgrading after upgrading from Realm v10.49.0 to v10.49.1.

After launching the app, the sync error RLMSyncErrorClientSessionError is passed into the closure at app.syncManager.errorHandler. The error does not contain any additional details.

The error is triggered by a RLM_ERR_CONNECTION_CLOSED that’s originating here:

https://github.com/realm/realm-core/blob/4eef991270a5e2161e37e8c227404327ac61f618/src/realm/sync/network/websocket.cpp#L1021

The SDK keeps trying to connect to Atlas Device Sync every few seconds and all attempts keep failing.

No log entries are shown in Atlas Device Sync for the device in question.

The error is reproducible on both Macs I’ve tested (Mac Studio and MacBook Pro, both with Apple Silicon) and on an iPad. One Mac is using wired Ethernet and the other devices are on Wi-Fi.

Can you reproduce the bug?

95% of the time. It first only appeared on the Macs, but after a few hours, the iPad started exhibiting the same behavior. If the app and all associated data is deleted from the device and then reinstalled, it will work fine the first time it is launched.

Version

10.49.1

What Atlas Services are you using?

Atlas Device Sync

Are you using encryption?

Yes

Platform OS and version(s)

macOS Sonoma 14.4.1 (23E224) iPadOS 17.4.1

Build environment

Xcode 15.4 Swift Package Manager

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Reactions: 1
  • Comments: 24 (1 by maintainers)

Most upvoted comments

@andreasley / @Jaycyn / @vishaldeshai / @anton-plebanovich / @KudeusVince FYI - there was a server fix to address this failure that you were seeing.

Under certain circumstances, (e.g. starting a sync websocket session with a cached user) the client will connect to the “global” MongoDB realm endpoint “https://realm.mongodb.com”, (or “https://services.cloud.mongodb.com” after the domain update), which would be translated to a localized server by the DNS based on your area. If the cloud app happens to reside on the localized server you connected to, everything was good. If not, then the server was responding with the WebSocket: Internal Server Error error and an arbitrary "error" message.

The server fix was to tell the client to connect to the correct localized server via a redirect response from the server instead of returning the error you were seeing.

As a result, your client app should no longer be required to specify the localized server base URL and it should “just work” without crashing.

@andreasley Not sure the issue being described is clear.

We also use User/Password Authentication and generally, getting an AppConfiguration is unrelated to the login process.

This code is working for us

let configuration = AppConfiguration(
   baseURL: "https://us-east-1.aws.realm.mongodb.com"
)

let gTodoApp = App(id: Constants.REALM_APP_ID, configuration: configuration)

and then the login is something like this

@MainActor
func login() async throws -> User {
    let creds = Credentials.emailPassword(email: "some email", password: "some password)
    let user = try await gTodoApp.login(credentials: creds)
    print("successfully logged in user: \(user)")
    return user
}

We also use User/Password Authentication and generally, getting an AppConfiguration is unrelated to the login process.

You’re absolutely right – I was looking at Realm.Configuration (which also takes a URL) instead of AppConfiguration. Using AppConfiguration(baseURL: "https://europe-west1.gcp.realm.mongodb.com") works perfectly fine as a workaround for me.

Apologies for the oversight. Thankfully, the weekend’s almost here. 😉