MirrorNetworking / MirrorNetworking/Telepathy

exception when disconnecting one of many clients in a console application

Open
#129 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
1.2k
Forks
141
PR merge metrics
No merged PRs in 30d

Description

It is possible to create multiple clients within a single console application (.NET 6 on Windows in my case). But if I create more than one client and then call Disconnect on the clients "usually" an error message including an exception is written to the console (see below).

When creating just one client that error does not appear. When creating two or three clients this error "sometimes" appears, but not always. When creating four or more clients this error "usually" appears, for some but not all created clients. This behavior obviously is not deterministic.

Attached is TelepathyExperiment.cs.txt which is a minimal example. In it the amount of created game clients is set as a command line parameter.

Am I using Telepathy in a wrong way? Is this expected behavior? Or is this not intended and could be fixed in Telepathy?

ReceiveLoop: finished receive function for connectionId=0 reason: System.Threading.ThreadInterruptedException: Thread was interrupted from a waiting state.
   at System.Threading.Monitor.ReliableEnter(Object obj, Boolean& lockTaken)
   at System.Resources.ResourceManager.AddResourceSet(Dictionary`2 localResourceSets, String cultureName, ResourceSet& rs)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
   at System.Resources.ResourceManager.GetString(String name)
   at System.SR.GetResourceString(String resourceKey)
   at System.SR.get_net_io_readfailure()
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Telepathy.NetworkStreamExtensions.ReadSafely(NetworkStream stream, Byte[] buffer, Int32 offset, Int32 size) in C:\MyProject\Telepathy\NetworkStreamExtensions.cs:line 18
   at Telepathy.NetworkStreamExtensions.ReadExactly(NetworkStream stream, Byte[] buffer, Int32 amount) in C:\MyProject\Telepathy\NetworkStreamExtensions.cs:line 55
   at Telepathy.ThreadFunctions.ReadMessageBlocking(NetworkStream stream, Int32 MaxMessageSize, Byte[] headerBuffer, Byte[] payloadBuffer, Int32& size) in C:\MyProject\Telepathy\ThreadFunctions.cs:line 55
   at Telepathy.ThreadFunctions.ReceiveLoop(Int32 connectionId, TcpClient client, Int32 MaxMessageSize, MagnificentReceivePipe receivePipe, Int32 QueueLimit) in C:\MyProject\Telepathy\ThreadFunctions.cs:line 121

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached TelepathyExperiment.cs.txt and reproduce disconnecting multiple clients on .NET 6. Trace the ThreadInterruptedException through ThreadFunctions.ReceiveLoop and NetworkStreamExtensions.ReadSafely/ReadExactly, then verify that disconnecting all clients no longer produces an unexpected console exception.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.