cyanfish / grpc-dotnet-namedpipes

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

CancellationTokenSource of ServerStreaming causes Memory leaking #55

Closed NeverMorewd closed 11 months ago

NeverMorewd commented 1 year ago

image

image

NeverMorewd commented 1 year ago

It seems that the cts from CreateLinkedTokenSource() need to be dispose manually. I has apply the workaround with adding using in front of var combined in MessageReader.cs

public async Task<bool> MoveNext(CancellationToken cancellationToken)
{
    try
    {
            using var combined =
            CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _callCancellationToken,
                _deadline.Token);
        return await _payloadQueue.MoveNext(combined.Token).ConfigureAwait(false);
    }
    catch (OperationCanceledException)
    {
        if (_deadline.IsExpired)
        {
            throw new RpcException(new Status(StatusCode.DeadlineExceeded, ""));
        }
        else
        {
            throw new RpcException(Status.DefaultCancelled);
        }
    }
}
NeverMorewd commented 1 year ago

refer: https://github.com/dotnet/runtime/issues/78180

cyanfish commented 11 months ago

Thanks, #56 merged and included in 3.0.0.