-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Bug: Messages duplicates (channel.send) under 100% server CPU load #6692
Comments
What I've found usually happens is that the socket will disconnect when it can't process anything(since node is single threaded) and if you have retries on after it reconnects, it probably re-sends it. You might be able to easily replicate it by putting a breakpoint in a debugger for your code and stepping over the |
@JMTK thanks for your input. I can't reproduce it with the debugger breakpoint, but trying to run my bot without the |
I have to add that removing |
I'd label this as an edge-case. It's never optimal to have the CPU at 100%, specially since it can lead to all kinds of unexpected behaviour, timeouts, high latency, etc. We use a timer to automatically abort requests after a [configurable] amount of time, as seen here: discord.js/src/rest/APIRequest.js Lines 70 to 78 in 3b14883
When Node.js's event loop is very busy, the timers can be inaccurate and either reject very early, or reject very late, and besides that, the serialization and processing of the payload to be later sent by When the timer reaches its end, the request is automatically aborted, and if That processing sadly happens independently of the To solve the 100% CPU usage, I recommend:
I hope you find this advice useful in solving your issue! |
@kyranet thx for the detailed description 👍 It helps me to understand what's happening. In general, I just wanted to understand if I can prevent it from happening while it's being reworked. However. it seems that it will be unreliable in any case. Will do the temp solution, running my heavy job not so often. It's not really a bug, so the issue could be closed. |
Issue description
I have an issue with messages duplication under high server CPU load. It happens not every time, hardly reproducible on my servers (reproduced once) but users of my bot report about 2-3-4 messages duplicates.
I checked plenty of things in my bot and think about some discord.js issue (or good thing went wrong), because I log related
channel.send
usage and in my logs, I get the message only once (I checked specifically cases when it was duplicated).So the discord.js somehow sends more messages with one
channel.send
and it happens only when CPU is close to 100%.I was on v12 and migrated to v13, the same story.
Current code:
channel.send({content: msg, embeds: embed ? [embed] : null})
in v12 it was
channel.send(msg, embed)
Additional info: I use
retryLimit: 5
in the Client constructor. However, from my understanding, it applies to cases when the bot gets 5xx errors and retries it. So it shouldn't be related to the issue.Codesample
No response
discord.js version
13.1.0
Node.js version
16.9.1
Operating system
Ubuntu 20.04.2 LTS
Priority this issue should have
Medium (should be fixed soon)
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
GUILD_MESSAGES
I have tested this issue on a development release
No response
The text was updated successfully, but these errors were encountered: