I have several asynchronous network operations that return a task that may never finish:
UdpClient.ReceiveAsync
doesn't accept aCancellationToken
TcpClient.GetStream
returns aNetworkStream
that doesn't respect theCancellationToken
onStream.ReadAsync
(checking for cancellation only at the start of the operation)
Both wait for a message that may never come (because of packet loss or no response for example). That means I have phantom tasks that never complete, continuations that will never run and used sockets on hold. I know i can use TimeoutAfter
, but that will only fix the continuation problem.
So what am I supposed to do?