iOS CB Lite Websocket Timeout, Reconnect Fails


Hello all,

In advance, I appreciate your time spent helping on this.

My iOS app is set up using CB Lite, reflecting the iOS ToDo replication example as best I can. I have the Sync Gateway implemented, along with a shadowing bucket on CB Server. I also have a server-side application that is set up to write new documents to the CB Server on demand. Here is the iOS code to start replication:

// Initialize Couchbase Replication
_push = database.createPushReplication(SyncGatewayURL)
_pull = database.createPullReplication(SyncGatewayURL)
_push.continuous = true
_pull.continuous = true

When I start up the iOS app, everything works really well. My server-side app writes to CB Server, and the changes are pushed to the iOS client. After several minutes though, the logging on the SG it appears to note that it closes the Socket to the iOS client with the following note:

10:28:30.957125 HTTP+: #265: --> WebSocket closed

At this point, the iOS client also logs that it has disconnected, then immediately attempts to reconnect:

2015-03-31 10:28:31.166 appName[648:1822315] CBLWebSocketChangeTracker[0x17d40c80 sync_gateway]: Connection error #1, retrying in 2.0 sec: Socket closed by remote peer

2015-03-31 10:28:33.168 appName[648:1822315] SyncVerbose: CBLWebSocketChangeTracker[0x17d40c80 sync_gateway]: GET //

At this point, however, the application never again updates the data in the app. No new logs are written unless the database changes on the iOS side and new changes are pushed. Even when the CB Server application writes new updates, the SG see’s them and “notifies” everyone, but the iOS client never see’s any updates thereafter.

Again, thank you for your help! Please let me know if additional details would be helpful.


Socket disconnects are usually caused by some intermediate proxy/gateway. Are you running SG on AWS? Their Elastic Load Balancer is infamous for doing this. However, Couchbase Lite expects this and, as you saw, reconnects. But it sounds like the reconnect isn’t working, somehow.

Do you ever get any further error logs on the client? I think it should be logging something to SyncVerbose if it fails to reconnect. If not, turn on the "WS" logging keyword and you’ll get lots of verbose junk about the WebSocket connection. Maybe there will be a clue there.


Great thought, I’ll start by reviewing the web socket’s logs.
I’ll add more information as I find it.

Thank you Jens,