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

Possible leaks in AsyncLock #142

Closed
RyanYANG52 opened this issue Apr 11, 2024 · 1 comment · Fixed by #143
Closed

Possible leaks in AsyncLock #142

RyanYANG52 opened this issue Apr 11, 2024 · 1 comment · Fixed by #143
Assignees
Labels
bug Something isn't working

Comments

@RyanYANG52
Copy link

Hi, @kekyo , I'm looking through your code,

ct.Register(() => tcs.TrySetCanceled());

here it registered a cancel callback, but it never dispose even when lock is acquired, ct would hold on to all the tcs until it's cancelled. In my case I create one CancellationTokenSource, only Cancel when the app is closed, if any race condition happen it would add a registration to the linked list inside cts

maybe add something like this:

        if (ct != default)
        {
            var registration = ct.Register(() => tcs.TrySetCanceled());
            tcs.Task.ContinueWith(_ => registration.Dispose(), TaskContinuationOptions.ExecuteSynchronously); // dispose registration after task completion
        }

I see it was done in AsyncEx lib

https://github.com/StephenCleary/AsyncEx/blob/master/src/Nito.AsyncEx.Coordination/AsyncWaitQueue.cs#L82

@kekyo kekyo added the bug Something isn't working label Apr 11, 2024
@kekyo kekyo self-assigned this Apr 11, 2024
@kekyo kekyo linked a pull request Apr 11, 2024 that will close this issue
@kekyo
Copy link
Owner

kekyo commented Apr 12, 2024

Thanks and fixed.

@kekyo kekyo closed this as completed Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants