MirrorNetworking / MirrorNetworking/Telepathy
"Cannot access a disposed object" thrown OnClientDisconnect()
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 141
- PR merge metrics
- No merged PRs in 30d
Description
Hi there.
This error only occurs:
- on the server.
- when the client disconnecting is NOT also a host. Hosts stop perfectly fine.
The error seems to be caused by the base implementation of 'OnStopClient' called from the base 'OnClientDisconnect' method.
I am using the Multiplex Transport but currently only have Telepathy running.
I've tried first removing the client's ownership of all their owned objects as well as the player object. This did not help.
Here is the log:
ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
at System.Net.Sockets.Socket.ThrowIfDisposedAndClosed () [0x0001b] in <8c9cb336fa2042c285391d24de6e4092>:0
at System.Net.Sockets.Socket.get_RemoteEndPoint () [0x00000] in <8c9cb336fa2042c285391d24de6e4092>:0
at Telepathy.Server.GetClientAddress (System.Int32 connectionId) [0x00014] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\Transports\Telepathy\Telepathy\Server.cs:324
at Mirror.TelepathyTransport.ServerGetClientAddress (System.Int32 connectionId) [0x00002] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\Transports\Telepathy\TelepathyTransport.cs:197
at Mirror.MultiplexTransport.ServerGetClientAddress (System.Int32 connectionId) [0x00011] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\Transports\MultiplexTransport.cs:224
at Mirror.NetworkConnectionToClient.get_address () [0x00000] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\NetworkConnectionToClient.cs:10
at CustomNetworkManager.OnServerDisconnect (Mirror.NetworkConnectionToClient conn) [0x00009] in D:\Unity\Repos\WitheredWillows\Assets\ScriptLibrary\GuardianOfElderidge\Networking\CustomNetworkManager.cs:51
at Mirror.NetworkServer.OnTransportDisconnected (System.Int32 connectionId) [0x00027] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\NetworkServer.cs:600
at Mirror.MultiplexTransport+<>c__DisplayClass18_0.<AddServerCallbacks>b__3 (System.Int32 baseConnectionId) [0x00001] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\Transports\MultiplexTransport.cs:194
at Mirror.TelepathyTransport.<ServerStart>b__27_2 (System.Int32 connectionId) [0x00000] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\Transports\Telepathy\TelepathyTransport.cs:173
at Telepathy.Server.Tick (System.Int32 processLimit, System.Func`1[TResult] checkEnabled) [0x00098] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\Transports\Telepathy\Telepathy\Server.cs:382
at Mirror.TelepathyTransport.ServerEarlyUpdate () [0x00010] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\Transports\Telepathy\TelepathyTransport.cs:229
at Mirror.MultiplexTransport.ServerEarlyUpdate () [0x00012] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\Transports\MultiplexTransport.cs:35
at Mirror.NetworkServer.NetworkEarlyUpdate () [0x00010] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\NetworkServer.cs:1717
at Mirror.NetworkLoop.NetworkEarlyUpdate () [0x00001] in D:\Unity\Repos\WitheredWillows\Assets\Plugins\Mirror\Runtime\NetworkLoop.cs:193
(Filename: D:/Unity/Repos/WitheredWillows/Assets/Plugins/Mirror/Runtime/Transports/Telepathy/Telepathy/Server.cs Line: 324)
Currently I just commented out line 324 in Telepathy.Server which has the trouble method 'GetClientAddress' as seen at the top of the stack above.
Please let me know what further information I can provide. Thanks in advance for any assistance!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Telepathy/Server.cs line 324, where GetClientAddress reads the client's remote endpoint during disconnection. Trace the callback path through TelepathyTransport.cs, MultiplexTransport.cs, and NetworkServer.cs, including the reported CustomNetworkManager.OnServerDisconnect call. Reproduce a non-host client disconnect and verify that the server no longer throws ObjectDisposedException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100