-
-
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
feat(WebSocketShard): heartbeat jitter #9223
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov Report
@@ Coverage Diff @@
## main #9223 +/- ##
==========================================
- Coverage 83.74% 83.67% -0.07%
==========================================
Files 100 100
Lines 9546 9552 +6
Branches 1101 1101
==========================================
- Hits 7994 7993 -1
- Misses 1513 1520 +7
Partials 39 39
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
const jitter = Math.random(); | ||
const firstWait = Math.floor(payload.d.heartbeat_interval * jitter); | ||
this.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better that we do it this way so we can clear it if needed because we won't be able to clear the sleep if we need to
this.heartbeatInterval = setInterval(async () => {
if (this.heartbeatInterval) clearInterval(this.heartbeatInterval);
this.heartbeat();
this.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);
}, payload.d.heartbeat_interval * Math.random());
Please describe the changes this PR makes and why it should be merged:
Puts us more in line with https://discord.com/developers/docs/topics/gateway#sending-heartbeats - where the impl prior to this PR effectively just meant a hardcoded jitter of
1
.Closes #9197
Status and versioning classification: