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

feat(WebSocketShard): heartbeat jitter #9223

Merged
merged 2 commits into from
Mar 12, 2023

Conversation

didinele
Copy link
Member

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:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@vercel
Copy link

vercel bot commented Mar 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
discord-js ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 12, 2023 at 7:24PM (UTC)
discord-js-guide ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 12, 2023 at 7:24PM (UTC)

@codecov
Copy link

codecov bot commented Mar 11, 2023

Codecov Report

Merging #9223 (2618048) into main (646b6ea) will decrease coverage by 0.07%.
The diff coverage is 0.00%.

❗ Current head 2618048 differs from pull request most recent head 1a27405. Consider uploading reports for the commit 1a27405 to get more accurate results

@@            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              
Flag Coverage Δ
next ∅ <ø> (∅)
ws 58.03% <0.00%> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/ws/src/ws/WebSocketShard.ts 22.00% <0.00%> (-0.23%) ⬇️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Jiralite Jiralite added this to the ws v0.7 milestone Mar 11, 2023
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`]);

Copy link

@darkyeg darkyeg Mar 15, 2023

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());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Implementation of Jitter in Heartbeat Interval is missing
6 participants