Sync Gateway returning "401 unauthorised" does not set lastError

Hi all,

I’ve noticed that if the user password changes in CB, a device that is syncing logs in the console (repeatedly):

2015-09-01 17:26:05.597 KetoDiet[1767:480216] CBLMultipartDownloader[/Cloud/Sync.ashx/ketodiet/CMI_BEAB9D51F53945D89904A69A101D7AC3]: Got error Error Domain=CBLHTTP Code=401 "401 unauthorized" UserInfo=0x174e74080 {NSURL=, NSLocalizedFailureReason=unauthorized, NSLocalizedDescription=401 unauthorized}

but, it never sets the pull or push lastError field…? I’m checking for these fields in my kCBLReplicationChangeNotification handler. They are both (push.lastError / pull.lastError) set to nil despite the 401 error returned from the server.

Any ideas?


seems this will correctly set lastError but the above won’t – is it that the CBLMultipartDownloader does not set lastError correctly…?

2015-09-01 18:16:53.522 KetoDiet[1767:480216] Replication: CBL_Puller[] took 4380.081 sec; error=Error Domain=CBLHTTP Code=401 "401 unauthorized" UserInfo=0x174e69b40 {NSURL=, NSLocalizedFailureReason=unauthorized, NSLocalizedDescription=401 unauthorized}

Thank you.

Can you describe what you’re doing in more detail? I can’t tell from the above whether you’re changing the password on the server or the client.

Also, does the replication keep working (pushing/pulling documents) despite the errors being logged?

You can get more details of what the replicator is doing internally, including state transitions, by enabling the Sync logging flag, as documented here. (For even more spew, enable SyncVerbose.)

So what I’m doing is that while the replication active… I change the password on the server through the ADMIN interface… almost instantly on the client I see the 401s and my assumption was that no data synced at that point but need to debug & confirm that.

Why do I change the password: i have a custom User DB (external) and a password reset on it propagates to a password change on the CouchDB it self (through the ADMIN interface). So, as a user, if I reset my password i would expect any on-going syncs to stop/fail until my new password is entered etc etc


OK, if you change the password on the server side, the client replications should definitely stop and set lastError to an HTTP 401 status. So this sounds like a bug. Could you please file an issue on GitHub? Make sure to include details like what version of CBL you’re using.

yes sure I will do - for now I found a way to force an error (use a custom reverse proxy which helps)

Thank you

I’ve found the problem, and filed an issue already to track it. Thanks for reporting this.

Thank you very much - you’ve always been incredibly helpful…!