Some users of my production app consistently get “Bad changeset (DOWNLOAD)” errors when using Realm Sync, even after re-installing the app.
The code of the sync error handler is the following (Swift):
realmApp.syncManager.errorHandler = { error, session in
let syncError = error as! SyncError
switch syncError.code {
case .clientResetError:
guard let (path, clientResetToken) = syncError.clientResetInfo(),
let realmFileURL = getClientResetRealmFileURL() else { return }
DispatchQueue.main.async {
let data = SyncErrorData(clientResetToken: clientResetToken, autoBackupPath: path, realmFileURL: realmFileURL, syncManager: realmApp.syncManager)
AppDelegate.shared.rootViewController.handleClientResetError(data: data)
}
case .clientUserError: // "expired refresh token" error, after 30 days
DispatchQueue.main.async {
AppDelegate.shared.rootViewController.handleSyncError(.expiredRefreshToken)
}
// In case of other errors, we do the same as for expired refresh token errors: log out the user
default:
AppDelegate.shared.rootViewController.handleSyncError(.unknown(syncError))
}
}
When getting this error, or any other kind of sync error, the user is logged out. But for this error, when users try to login again, they get the same error (even if they uninstall and re-install the app).
The error on the server is:
Error:
ending session with error: integrating 1 changesets failed after 1 attempts in 7.540692071s: could not complete upload integration as this connection no longer owns the file ident; no action is needed, as the client has already established a new connection to the sync server to complete its upload (ProtocolErrorCode=201)
Logs:
[ "Session was active for: 10s" ]
Partition:
PUBLIC
Session Metrics:
{ "uploads": 1, "downloads": 1 }
Remote IP Address:
81.102.24.215
SDK:
Realm Cocoa v10.15.1
Platform Version:
Version 15.1 (Build 19B74)
The important part (I guess) is could not complete upload integration as this connection no longer owns the file ident
, but I don’t understand what it means. The part that troubles me is “no action is needed, as the client has already established a new connection to the sync server to complete its upload”, which seems to indicate that this shouldn’t be an error.
It’s also worth noting that before getting this specific error, users got another error for a few months, “Bad progress information (DOWNLOAD)”, which also prevented them from using the app.
I’m guessing the source of the problem is a schema inconsistency, however this should be resolved by now. My concern is that such errors should be solved by doing a client reset, which is not the case here.
How to get sync to work again for those users?