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
10.49.1 failing to connect to Atlas Device Sync #8531
Comments
➤ PM Bot commented: Jira ticket: RCOCOA-2324 |
The problem seems to be that the SDK is trying to connect to the wrong host.
My suspicion: The URL is only updated if the user token is missing or expired. This bug may have been introduced in realm/realm-core@255cb33. |
I think I duplicated this issue and was seeing the same thing. However, right in the middle of typing this, it seemed to resolve itself. The issue appeasrs to revolve around running the app with an already authenticated user - it seemed to be trying to connect to an incorrect endpoint. I had to log out and log back in and then it worked and connected to the correct endpoint. Can you try your code again and see if it's an ongoing issue? |
Well, let me retract my above comment as it's doing it again. After updating to 10.49.1 the app does not connect and the only error shown (in the app) was
Upon checking the Logs in the Realm Console, there was no error. I then re-ran the app (with logged the user out), logged in and it connected and worked correctly. No further issues. However, if I quit the app while still authenticated, and then re-run the app, it attempts to connect but then fails with the same above error. I have to log out and log back in to connect. I can verify the endpoint it attempts to connect to when starting the app with an already-authenticated user is different than the connection if I log out and log back in - maybe that's by design? Here's what I see if logging in, quitting and re-running the app Here's what I see if I log out, quit the app, re-run it and log back in There are no errors in the console at all - but that being said, the endpoint doesn't seem to the correct one if the user is already authenticated upon trying to connect My endpoint looks like Info: Connection[1]: Connecting to 'wss://ws.us-east-1.aws.realm.mongodb.com:443/api/client/v2.0/app/my_cool_app-xyzzy/realm-sync' Is this a coding issue on our end or a SDK issue? If it's determined to be a coding, we are using the code to log in from the documentation and can supply that. |
We are facing exactly the same issue, please help |
After migrating version to 10.49.1, we also faced the same error.
|
I have the same error after updating to
|
➤ marysiapietraszewska commented: [~jason.flax@mongodb.com] [~jonathan.reams@mongodb.com] can you take a look at it? |
Hi @andreasley, This looks like it is related to the latest base URL changes added recently - the websocket will try to connect to the default websocket address determined by the provided When you log in before starting the sync session with the cloud, the location info was already queried/updated per the log in request to the server. The websocket connection is a bit different, since it uses a different code path/underlying driver and updating the location takes a bit more coordination. I am working on a couple of fixes around this area, but a temporary workaround, for now, would be to specify the localized base_url value (e.g. |
Thanks for looking into this, @michael-wb.
|
You can configure the baseUrl in swift using |
Thank you @michael-wb For those of us not familiar with directly working with App Services, since the workaround is to create a custom AppConfiguration, what values do the other parameters need to be set to? From the docs
can they stay the same as in the docs per above? If not what should the values be? |
Hi @Jaycyn
API reference: https://www.mongodb.com/docs/realm-sdks/swift/latest/Extensions/AppConfiguration.html |
Original code which logs in and out correctly
new code
results in
I am sure I am overlooking something but it's not clear where I should begin looking since only one line of code was changed. |
Oh, sorry - try removing the |
That corrected the issue and it appears to be working. Thank you for the super fast responses. |
But there was some issue related to meta data version in earlier version. |
Unfortunately, my app is using User/Password authentication and I have to use |
@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
and then the login is something like this
|
You're absolutely right – I was looking at Apologies for the oversight. Thankfully, the weekend's almost here. ;) |
@andreasley / @Jaycyn / @vishaldeshai / @anton-plebanovich / @KudeusVince 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 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. |
@michael-wb I have tried with the latest First run
Seconds run
Third run
|
This is the intended behavior. The websocket connection is established against the default url, after which the server responds with the local url that should be used. Why do you believe this is a workaround that needs to be fixed? |
@nirinchev Longer overall connection duration: 2-3 seconds for subsequent runs versus 1 second for the initial run in my case. As an optimization, it may preserve the returned URL instead of always trying the default URL and failing. Currently, the logic I have uses cached user to speed up application startup but with the new behavior it looks like login every time is actually faster startup flow which is counterintuitive and killing optimizations I have. This is the old framework behavior which takes only 1 second to finish the connection without errors:
Updating to the new framework version causes longer overall connection time and so is regression and update blocker from my point of view. |
@anton-plebanovich - understood. If the sync time from app start is a priority/concern, the best method is to specify the localized server, since you will connect directly to the appropriate server on the first attempt. |
Thank you @michael-wb I verified the solution and it works for me 👍 |
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 atapp.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
The text was updated successfully, but these errors were encountered: