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

DB022 crashes UWP app when closing WebSocket at end of replication #975

Closed rainerg2000 closed 6 years ago

rainerg2000 commented 6 years ago

In my UWP test app running on Windows 10 1709 I run a couple of test cases that exercise Push, Pull and PushPull replications.

In this file (encrypted for @borrrden ) I collected some logs from couchbase-lite-core and from Sync Gateway: https://drive.google.com/file/d/1ov8sE08zsqUX6waP3AjeUWCEAESiYt2A/view?usp=sharing Files with 'bad' in the name are from several identical sessions that ended with a crash. Files with 'good' in the name are from several identical sessions that ended without a crash.

Here's a stack trace

LiteCore.dll!litecore::websocket::WebSocketImpl::onClose(litecore::websocket::CloseStatus status) Line 352  C++ Symbols loaded.
LiteCore.dll!c4socket_closed(C4Socket * socket, C4Error error) Line 241 C++ Symbols loaded.
[Managed to Native Transition]      Annotated Frame
Couchbase.Lite.dll!LiteCore.Interop.SocketFactory.SocketCompletedReceive(LiteCore.Interop.C4Socket* socket, System.UIntPtr byteCount) Line 196  C#  Symbols loaded.
[Native to Managed Transition]      Annotated Frame
LiteCore.dll!litecore::websocket::C4Provider::receiveComplete(litecore::websocket::WebSocketImpl * s, unsigned int byteCount) Line 188  C++ Symbols loaded.
LiteCore.dll!litecore::websocket::WebSocketImpl::onReceive(fleece::slice data) Line 188 C++ Symbols loaded.
LiteCore.dll!c4socket_received(C4Socket * socket, FLSlice data) Line 249    C++ Symbols loaded.
[Managed to Native Transition]      Annotated Frame
Couchbase.Lite.dll!LiteCore.Interop.Native.c4socket_received(LiteCore.Interop.C4Socket* socket, byte[] data) Line 64    C#  Symbols loaded.
Couchbase.Lite.dll!Couchbase.Lite.Sync.WebSocketWrapper.Receive.AnonymousMethod__2() Line 343   C#  Symbols loaded.
Couchbase.Lite.dll!Couchbase.Lite.Support.SerialQueue.ProcessAsync() Line 179   C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.Tasks.Task.InnerInvoke() Line 2854   C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.Tasks.Task.Execute() Line 2472   C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj) Line 2831    C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 104   C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) Line 2794 C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) Line 2730  C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.Tasks.ThreadPoolTaskScheduler.LongRunningThreadWork(object obj) Line 44  C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Line 71   C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 104   C#  Symbols loaded.
System.Private.CoreLib.ni.dll!System.Threading.ThreadHelper.ThreadStart(object obj) Line 90 C#  Symbols loaded.
[Native to Managed Transition]      Annotated Frame
kernel32.dll!@BaseThreadInitThunk@12() Unknown Symbols loaded.
ntdll.dll!__RtlUserThreadStart()    Unknown Symbols loaded.
ntdll.dll!__RtlUserThreadStart@8() Unknown Symbols loaded.
borrrden commented 6 years ago

I am pretty sure I have found and fixed this already (related to #965 in that after anything goes wrong during a close, the "finally" block will attempt to close an already disposed object resulting in a native crash)

djpongh commented 6 years ago

closing based on comment from @borrrden , above.