icerpc / icerpc-csharp

A C# RPC framework built for QUIC, with bidirectional streaming, first-class async/await, and Protobuf support.
https://docs.icerpc.dev
Apache License 2.0
108 stars 13 forks source link

ReadSequence warnings #410

Closed pepone closed 3 years ago

pepone commented 3 years ago

https://github.com/zeroc-ice/icerpc-csharp/blob/d6e781f84a3a95bbf45ff248844e3562b8667b36/src/IceRpc/Internal/TelemetryDispatcher.cs#L89

Calling the above method produces the following warning, we didn't catch it earlier because this was disabled in the analyzer

Severity    Code    Description Project File    Line    Suppression State   Detail Description
Warning CA2000  Call System.IDisposable.Dispose on object created by 'reader.ReadSequence(' before all references to it are out of scope    IceRpc  D:\IceRPC\icerpc-csharp\src\IceRpc\Internal\TelemetryDispatcher.cs  90  Active  If a disposable object is not explicitly disposed before all references to it are out of scope, the object will be disposed at some indeterminate time when the garbage collector runs the finalizer of the object. Because an exceptional event might occur that will prevent the finalizer of the object from running, the object should be explicitly disposed instead.

As pointed by @bernardnormier the problem seems to be CollectionBase<T> implements IEnumerator<T>, which is IDisposable

bernardnormier commented 3 years ago

I would try to fix it by implementing the IEnumerator<T> using a separate struct.