Network icon indicating copy to clipboard operation
Network copied to clipboard

A Task was cancelled

Open rizuruu opened this issue 3 years ago • 7 comments

Hi. The server randomly throws this exception anytime. The last time I found it was when no client was connected. What should be done?

image

rizuruu avatar Feb 21 '22 00:02 rizuruu

Stop trying to send packets over a dead connection.

Toemsel avatar Feb 21 '22 08:02 Toemsel

Stop trying to send packets over a dead connection.

Doesn't it automatically stop on calling connection.Close() on both sides?

rizuruu avatar Feb 21 '22 11:02 rizuruu

It closes, but packets in the send-queue still try to make it through. The lib embraces a pretty slim state machine: ONLINE, OFFLINE. That's it. Everything before and after has to be considered in your code.

In your case, I assume the connection dies while sending a paket. (e.g. the sent packet is faulty)

If you think this behavior isn't intended or even a bug, please set up a small example project for further analysis.

Toemsel avatar Feb 21 '22 11:02 Toemsel

It closes, but packets in the send-queue still try to make it through. The lib embraces a pretty slim state machine: ONLINE, OFFLINE. That's it. Everything before and after has to be considered in your code.

In your case, I assume the connection dies while sending a paket. (e.g. the sent packet is faulty)

If you think this behavior isn't intended or even a bug, please set up a small example project for further analysis.

Yeah, technically connection dies when the server is sending client a packet because connection might have closed on client side. Possibly comes from this part of code. image

I use it to check if the client is still available on the network. If an exception happens, I quickly close the connection. Do you think there still should be an issue?

rizuruu avatar Feb 21 '22 12:02 rizuruu

I see. You might want to check whether the connection is still alive before you call connection.Close() Moreover, there is no need to perform pings manually. That is already a part of the lib itself. (It checks when the client/server is not reachable anymore) All you have todo is to subscribe to an event: connection.ConnectionClosed

You can configure the TIMEOUT (default 2.5 sec) or disable the pinging completely.

Toemsel avatar Feb 21 '22 12:02 Toemsel

Are you talking about connection.SendPing()? It's probably not awaited call and doesn't have a response either. So will it cause an exception in try catch for detection of ping fail?

And yes I already have subscribed to the ConnectionClosed event. image

The initial exception randomly happened long after server was left without any clients. I tried to regenerate the exception by leaving it with 0 clients. Also tried to rapidly connect and disconnect connections but couldn't generate it. It randomly happens and sadly ends up crashing the application since its self contained build.

rizuruu avatar Feb 21 '22 12:02 rizuruu

Strange. I have to test this case on my machine. So, in order to reproduce the issue, one has to:

  1. Connect a client
  2. Disconnect the client (force or via .close())
  3. Server experiences exception

// flaggy issue - doesn't occur all the time

Toemsel avatar Feb 21 '22 12:02 Toemsel