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 because of Task.Delay(-1, token) #149

Open
davideberli opened this issue Nov 10, 2022 · 3 comments
Open

Memory leak because of Task.Delay(-1, token) #149

davideberli opened this issue Nov 10, 2022 · 3 comments
Assignees

Comments

@davideberli
Copy link

Task.Delay(-1, token) is creating a Task for every client that is running forever:

var cancellationTask = Task.Delay(-1, token);

A quick and dirty workaround would be this:

private async Task<bool> DelayTask(CancellationToken token1, CancellationToken token2)
{
       while (!token1.IsCancellationRequested && !token2.IsCancellationRequested)
       {
            await Task.Delay(100);
       }

        return true;
}

public async Task<TcpClient> WaitAnyTcpClientAsync(CancellationToken token)
{
      var tokenToDispose = new CancellationTokenSource();
      var cancellationTask = Task.Run(() => DelayTask(token, tokenToDispose.Token));
      
      do
       {
          ...
       }
       while (result == null);
       
       tokenToDispose.Cancel();
}
@fubar-coder fubar-coder self-assigned this Nov 11, 2022
@michi927
Copy link

michi927 commented Apr 12, 2023

An update with a fix for this memory leak whould be very nice. I occur the same issue...

Is there already a date when this package gets updated @fubar-coder ? :)

@AndreasKue
Copy link

Push

@LodiAleardo
Copy link

U
P
💯

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

5 participants