IAsyncStreamReader.MoveNext() in bidirectional stream can not be cancelled by a CancellationToken
lumieru opened this issue · 2 comments
lumieru commented
in receive thread:
IAsyncStreamReader<ServerMsg> responseStream;
CancellationToken cancelToken; // cancelToken = source.Token
try {
while (await responseStream.MoveNext(cancelToken)) {
...
}
} catch(Exception e) {
...
}
in other thread
CancellationTokenSource source;
source.Cancel();
after call Cancel(), the receive thread should get an exception and quit the while loop. But actually nothing happened.
doctorseus commented
Hi @lumieru ,
thanks for submitting the ticket. I added additional code to allow testing this case e7a5cac. However, here in both cases, so server streaming and bi-directional streams, the call gets cancelled immediately from what I can tell. It would be great if you could provide some additional information when this happens, or even better, if you would be able to reproduce the issue with the example code shipping with the project, then I could take another look.
lumieru commented
You are right. It can be cancelled by a CancellationToken. I used it in a wrong way.