Sync Gateway returns 401 if couchbase server is down (instead of 5xx)
hermitdemschoenenleben opened this issue · 3 comments
I'm working on a mobile app that connects to Couchbase Sync Gateway using Pouchdb. If CSG replies to any request with status code 401 I assume that the user's login credentials have changed and that the user is logged out now.
A few days ago, we had a network problem on our servers which disrupted the connection between CSG and couchbase server. During this time, all active users were logged out (even though their credentials were still valid, of course). Apparently, CSG replied to every request with 401 even though a 5xx error would be more appropriate in this case.
On a staging server, I tested what happens when accessing CSG after shutting down couchbase server (for testing, I called the all_docs
endpoint). Indeed, I received 401 with content
{
"error": "Unauthorized",
"reason": "Invalid login"
}
Unfortunately, this is exactly the same response I get when a user's credentials have changed. This means that I don't see a way to discriminate between "server is down" and "user is logged out" which is bad because I don't want all of my users to be logged out when the server is down.
Sync Gateway version
2.8.3
Expected behavior
If CSG loses connection to couchbase server, it should return status code 5xx instead of 401.
Steps to reproduce
- Fetch
_all_docs
endpoint with basic auth and existing credentials --> it works - Shut down couchbase server
- Try again after a few seconds: request takes several seconds to complete and returns 401 instead of 5xx
Update: Apparently the _session
endoint correctly returns 503 with content
{
"error": "Service Unavailable",
"reason": "Database timeout error (gocb.ErrTimeout)"
}
if couchbase server is down. I'd expect the same behavior from other endpoints
This change makes sense - thanks for filing the issue. Have moved to https://issues.couchbase.com/browse/CBG-1872 for tracking.