cyanfish / grpc-dotnet-namedpipes

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

CancellationTokenSource of ServerStreaming causes Memory leaking #55

Closed NeverMorewd closed 6 months ago

NeverMorewd commented 8 months ago

image

image

NeverMorewd commented 8 months 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 8 months ago

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

cyanfish commented 6 months ago

Thanks, #56 merged and included in 3.0.0.