dotnet-architecture / grpc-for-wcf-developers

gRPC for WCF Developers guidance samples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AwaitCancellation usage in FullStockTickerService

davidkarlsson opened this issue · comments

In the FullStockTickerService example that uses bidirectional streaming it feels to me like the use of the AwaitCancellation() method that creates a task that completes when the CancellationToken of the ServerCallContext is cancelled is unneccesary and has just been caried over from the example with the single stream without much thought.

Why not just await the HandleActions() method directly there since its task also completes when the same CancellationToken is cancelled?

Furthermore, if an exception is thrown in the HandleActions() method for some reason in a more complex example it will not cancel the CancellationToken and the program will stop reading new actions but the program will not stop because it will continue waiting for the token to be cancelled at the call to AwaitCancellation(). This seems rather dangerous to me in a real world scenario.