[C#] Can I avoid InvalidOperationException "Already finished" in server code?

32 views
Skip to first unread message

andre.k...@gmail.com

unread,
Feb 25, 2020, 6:24:30 AM2/25/20
to grpc.io

Hi,
while implementing the server side of a server-streaming call (rpc TimeChanged(TimeChangedRequest) returns (stream TimeChangedResponse)),
I noticed that IAsyncStreamWriter<T>.WriteAsync(T message) sometimes throws an InvalidOperationException with the message "Already finished". This seems to happen after the client canceled the stream.
This exception is even thrown while the Task that handles the stream request on the server is still active.

Is it somehow possible to avoid this exception. Like there is int.Parse with Exceptions and int.TryParse without it?

Jan Tattermusch

unread,
Mar 17, 2020, 8:48:08 AM3/17/20
to grpc.io
I think this is basically https://github.com/grpc/grpc/issues/9377
Reply all
Reply to author
Forward
0 new messages