cyanfish / grpc-dotnet-namedpipes

Named pipe transport for gRPC in C#/.NET
Apache License 2.0
190 stars 48 forks source link

Server stream has not been notified when the client has been unexpectedly terminated. #30

Closed ychumpov closed 1 year ago

ychumpov commented 3 years ago

Here is my code:

public override async Task TestMethod(Empty request, IServerStreamWriter responseStream, ServerCallContext context) { logger.LogInfo($"request was registered!");

        // Completing the method means disconnecting the stream by server side. 
        // So just waiting the client to disconnect.
        var cts = new CancellationTokenSource();
        context.CancellationToken.Register(() =>
        {
            // This code was not called when the client has been killed.
            logger.LogInfo($"Subscription finished");
            cts.Cancel();
        });

        await AwaitCancellation(cts.Token);

}

private static Task AwaitCancellation(CancellationToken token) { var completion = new TaskCompletionSource(); token.Register(() => completion.SetResult(null)); return completion.Task; }

cyanfish commented 1 year ago

This should be fixed in 2.1.0.