Nethereum icon indicating copy to clipboard operation
Nethereum copied to clipboard

CancellationTokenSource in RpcClient not disposed. It would result in a leaked Timer object.

Open timaiv opened this issue 2 years ago • 0 comments

CancellationTokenSource should be disposed. Since we use timer (CancelAfter) it must be disposed properly.

https://github.com/Nethereum/Nethereum/blob/d1edf622614fb935ac8809a4b344b1b94d3a1820/src/Nethereum.JsonRpc.RpcClient/RpcClient.cs#L116C17-L117C1

https://stackoverflow.com/questions/6960520/when-to-dispose-cancellationtokensource http://web.archive.org/web/20160203062224/http://blogs.msdn.com/b/pfxteam/archive/2012/03/25/10287435.aspx https://github.com/dotnet/runtime/blob/aaab1701493d2e3bf392cac79f95a167039c9250/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs#L427 https://github.com/dotnet/runtime/blob/aaab1701493d2e3bf392cac79f95a167039c9250/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs#L539

Expected Behavior

using var cancellationTokenSource = new CancellationTokenSource(); or cancellationTokenSource.Dispose() (in try finally)

Current Behavior

var cancellationTokenSource = new CancellationTokenSource(); Dispose missing.

Context (Environment)

4.15.2

timaiv avatar Aug 02 '23 09:08 timaiv