WatsonTcp icon indicating copy to clipboard operation
WatsonTcp copied to clipboard

Unable to disconnect while stream is pending

Open Niproblema opened this issue 3 years ago • 4 comments

SendAsync runs until other peer reads the whole stream. This tends to be problematic, since, what if the other peer does not care about the whole stream? What to do then? Is there anyway to close stream, so that the sender receives true from SendAsync() ?

Also calling disconnect from client, while SendAsync stream is pending, does not work. It's just stuck there. In case server peer does not fully read the stream, that means deadlock for the client.

Niproblema avatar Mar 07 '22 15:03 Niproblema

Hi @Niproblema the reason it blocks is because it queues a message to send to the server indicating that the socket is being shut down. I'll amend this to provide a means of non-gracefully disconnecting by bypassing sending this message.

jchristn avatar Mar 09 '22 21:03 jchristn

Please let me know if this resolves the issue. On the client side you can call Disconnect(false) and it will bypass queuing the disconnect message.

NuGet: https://www.nuget.org/packages/WatsonTcp/4.8.14.9 Commit: https://github.com/jchristn/WatsonTcp/commit/f06e05142234a1b9bb27416997e525e1aee3d68b

jchristn avatar Mar 09 '22 21:03 jchristn

Hi @jchristn I checked your solution and while client side it works, server side receives no notification that client has disconnected. I understand why this is the case, but it also makes it impossible for server to track how many clients there really are connected.. Or is there anyother way? TCP should be able to monitor disconnect, no?

By the way, do you have a suggestion for

SendAsync runs until other peer reads the whole stream. This tends to be problematic, since, what if the other peer does not care about the whole stream? What to do then? Is there anyway to close stream, so that the sender receives true from SendAsync()

Niproblema avatar Mar 15 '22 10:03 Niproblema

Hi @Niproblema sorry for the delay. To make sure I understand the problem, are you implying that you want to:

  1. Client sends a message with a very large stream
  2. Server starts receiving
  3. During the receive, a disconnect operation is performed against the client

Please let me know if I have it right.

jchristn avatar Aug 15 '22 21:08 jchristn

Closing as abandoned.

jchristn avatar Nov 28 '22 21:11 jchristn