Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in RestClient.ExecuteInternal #1685

Closed
DanWatkins opened this issue Jan 7, 2022 · 4 comments
Closed

Memory leak in RestClient.ExecuteInternal #1685

DanWatkins opened this issue Jan 7, 2022 · 4 comments

Comments

@DanWatkins
Copy link

There appears to be a small memory leak in RestClient.ExecuteInternal caused by the following code:

var timeoutCts = new CancellationTokenSource(request.Timeout > 0 ? request.Timeout : int.MaxValue);
var cts        = CancellationTokenSource.CreateLinkedTokenSource(timeoutCts.Token, cancellationToken);

CancellationTokenSource does not have a finalizer, so my understanding is it needs to be explicitly disposed. I have made a custom build of RestSharp that adds using statements as shown below. This change fixes the leak.

using var timeoutCts = new CancellationTokenSource(request.Timeout > 0 ? request.Timeout : int.MaxValue);
using var cts        = CancellationTokenSource.CreateLinkedTokenSource(timeoutCts.Token, cancellationToken);

My application is making a high volume of requests, so this leak causes the system to run out of memory in about 2 hours.

Expected Behavior

No leaked memory

Actual Behavior

Leaked memory

Steps to Reproduce the Problem

  1. Execute a request using RestClient
  2. Profile using dotMemory by JetBrains

Specifications

  • Version: 107.0.0-preview.17
  • Platform: Windows 10, Ubuntu 20.04 (.NET 6)
@alexeyzimarev
Copy link
Member

Thanks. I will look at it.

@alexeyzimarev
Copy link
Member

Check 107.0.2-alpha.0.4 if it fixes the issue.

@DanWatkins
Copy link
Author

Thanks for the fast fix. Unfortunately I seem to be stuck on 107.0.0-preview.17 due to the encoding changes in 107.0.0-preview.18. I commented on #1687.

@alexeyzimarev
Copy link
Member

Closing as the fix is implemented, will be released in the next stable version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants