RevenantX / LiteNetLib

Lite reliable UDP library for Mono and .NET
https://revenantx.github.io/LiteNetLib/index.html
MIT License
3k stars 489 forks source link

ObjectDisposedException with Native Sockets #542

Closed ProbablePrime closed 5 months ago

ProbablePrime commented 5 months ago

Library version: 1.2.0

Framework: Mono

OS: Linux (Ubuntu)

I'm periodically seeing System.ObjectDisposedException on one of our servers:

Jan 28 06:17:32 skyfrostepyc mono[1766650]: System.ObjectDisposedException: Cannot access a disposed object.
Jan 28 06:17:32 skyfrostepyc mono[1766650]: Object name: 'System.Net.Sockets.Socket'.
Jan 28 06:17:32 skyfrostepyc mono[1766650]:   at System.Net.Sockets.Socket.ThrowIfDisposedAndClosed () [0x00021] in <a85c1a570f9a4f9f9c3d2cfa5504e34f>:0
Jan 28 06:17:32 skyfrostepyc mono[1766650]:   at System.Net.Sockets.Socket.get_Available () [0x00000] in <a85c1a570f9a4f9f9c3d2cfa5504e34f>:0
Jan 28 06:17:32 skyfrostepyc mono[1766650]:   at LiteNetLib.NetManager.NativeReceiveLogic () [0x000b8] in <e81faa18cf324359b43439ea5edb0a78>:0
Jan 28 06:17:32 skyfrostepyc mono[1766650]:   at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00017] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
Jan 28 06:17:32 skyfrostepyc mono[1766650]:   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <12b418a7818c4ca0893feeaaf67f1e7f>
Jan 28 06:17:32 skyfrostepyc mono[1766650]:   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
Jan 28 06:17:32 skyfrostepyc mono[1766650]:   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00031] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
Jan 28 06:17:32 skyfrostepyc mono[1766650]:   at System.Threading.ThreadHelper.ThreadStart () [0x0000b] in <12b418a7818c4ca0893feeaaf67f1e7f>:0

It looks like the Available property of a socket can also throw ObjectDisposedException

Which is not caught in NativeReceiveLogic

ProbablePrime commented 5 months ago

Thank you!