discord-net / Discord.Net

An unofficial .Net wrapper for the Discord API (https://discord.com/)
https://discordnet.dev
MIT License
3.32k stars 737 forks source link

[Bug]: RequestQueue leak #2677

Open nvmp-main opened 1 year ago

nvmp-main commented 1 year ago

Check The Docs

Verify Issue Source

Check your intents

Description

We use Discord.Net in a game server application that runs for days at a time, and after a while our performance slowly starts to degrade. Whilst I have been investigating memory dumps of our managed environment, we are seeing lots of tasks awaiting execution or are pending execution waiting inside Discord.Net.Queue.RequestQueue.RunCleanup. This doesn't seem right to us to have a lot of these tasks in memory waiting in this code, they even persist when we have no active clients in our server.

image

It may seem that looking at the implementation of RequestQueue, that it is not being correctly disposed of when used a member of RequestBucket. I am not overly familiar with this code, but it would potentially make sense to why there are so many tasks still waiting for cancellation via the disposable interface.

Version

3.10.0

Working Version

No response

Logs

image

Sample

No response

Packages

N/A

Fyers commented 1 year ago

I have the same problem on a project. Hunderts if not thousends of Tasks are waiting and new Tasks are not being run, hanging the service.

quinchs commented 1 year ago

My only guess here is that the token source responsible for exiting the RunCleanup task is disposed before waiting for the task to complete. I'll create a branch for you to test out to see if my potential fix works.

Have a play with https://github.com/discord-net/Discord.Net/tree/fix/request-queue-leak and let me know if the problem persists

Fyers commented 1 year ago

Have a play with https://github.com/discord-net/Discord.Net/tree/fix/request-queue-leak and let me know if the problem persists

Sorry for the late response. Is there any NuGet Package Version for this or do I have to build it myself?

Misha-133 commented 1 year ago

Sorry for the late response. Is there any NuGet Package Version for this or do I have to build it myself?

You'd need to build it yourself. Clone the repo, checkout the branch & do dotnet build

Misha-133 commented 10 months ago

@Fyers Any updates on this?

Fyers commented 10 months ago

@Fyers Any updates on this?

We no longer encounter this issue. I did not build the branch and we are using latest 3.13.0 nuget.