couchbase / couchbase-lite-net

A lightweight, document-oriented (NoSQL), syncable database engine for .NET
http://developer.couchbase.com/mobile/
Apache License 2.0
439 stars 126 forks source link

CB.Lite 2.0.0-db021 System.Net.Sockets.SocketException in SerialQueue during one-shot replication #952

Closed bdgza closed 6 years ago

bdgza commented 6 years ago

Couchbase.Lite 2.0.0-db021 in .NET Standard 2.0 project, part of Xamarin Forms 2.5.0.122203 app, running iOS 11.2 in Simulator.

I connect to the Gateway (Couchbase Sync Gateway/1.5.1(4;cb9522c)) for a manual pull/push replication, after Start(), and receiving a status of Connecting, the exception below happens. Although it has happened to me several times, I haven't been able to consistently reproduce it. It usually happens after the app has been open for a bit, at least some minutes, and has had several manual replications.

After the exception the replication does not continue, and will let the app wait forever. I would expect the exception not to occur, or fail the replication in a way that notifies the app of the failure.


14:20:13.923853 WARNING: (SerialQueue) [303] 2018-01-30T14:20:13.9210960+00:00 Exception during DispatchAsync: System.Net.Sockets.SocketException (0x80004005): System call failed
  at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00064] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs:167 
  at System.Net.Sockets.TcpClient.initialize () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/System/net/System/Net/Sockets/TCPClient.cs:608 
  at System.Net.Sockets.TcpClient..ctor (System.Net.Sockets.AddressFamily family) [0x00046] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/src/mono/mcs/class/referencesource/System/net/System/Net/Sockets/TCPClient.cs:86 
  at Couchbase.Lite.Sync.WebSocketWrapper.<Start>b__24_0 () [0x00009] in C:\jenkins\workspace\couchbase-lite-net\couchbase-lite-net\src\Couchbase.Lite\Sync\WebSocketWrapper.cs:122 
  at Couchbase.Lite.Support.SerialQueue.ProcessAsync () [0x0002f] in C:\jenkins\workspace\couchbase-lite-net\couchbase-lite-net\src\Couchbase.Lite\Support\SerialQueue.cs:178 ```
borrrden commented 6 years ago

Do the Sync Gateway logs say anything? And to confirm, the status changed callback does not happen? On the surface this looks like a simple inability to establish a socket connection with the other side so I would expect the answer to the first one to be no. Any time the replication suffers a failure like this it should stop and inform via the status callback though, so if it's not I'll fix that.

borrrden commented 6 years ago

By the way what is the exception? I see a stack trace but not the actual exception details.

bdgza commented 6 years ago

The Sync Gateway does not log anything. The exception happens inside the Couchbase library and the stacktrace gets logged to console. Nothing comes back, no exception, no status change happens.

borrrden commented 6 years ago

The exception happens inside the Couchbase library and the stacktrace gets logged to console

The excerpt you have given me seems incomplete. Is it really just a stack trace with no exception above it?

bdgza commented 6 years ago

I updated the comment, markdown had cut off the first line.

borrrden commented 6 years ago

Thanks I can see the message now.

borrrden commented 6 years ago

I very naively thought I was catching exceptions by wrapping the whole call to Start() inside of a try catch but that won't work because it is an async method so by the time the exception is reached it is already on another thread. I'll fix up this particular case real quick and then go hunting for other cases.