From 6ee061d8745a270d79c382a41c68912dcbdadbfd Mon Sep 17 00:00:00 2001 From: Skillz Date: Wed, 15 Mar 2023 15:59:03 -0500 Subject: [PATCH] fix: prevent multiple heartbeats --- packages/gateway/src/Shard.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/gateway/src/Shard.ts b/packages/gateway/src/Shard.ts index 3ba9f9ee0..746c3a715 100644 --- a/packages/gateway/src/Shard.ts +++ b/packages/gateway/src/Shard.ts @@ -10,6 +10,7 @@ import type { } from '@discordeno/types' import { GatewayCloseEventCodes, GatewayIntents, GatewayOpcodes } from '@discordeno/types' import { Collection, LeakyBucket, camelize, delay, logger } from '@discordeno/utils' +import { clearInterval } from 'node:timers' import { inflateSync } from 'node:zlib' import WebSocket from 'ws' import type { RequestMemberRequest } from './manager.js' @@ -505,7 +506,9 @@ export class DiscordenoShard { /** Start sending heartbeat payloads to Discord in the provided interval. */ startHeartbeating(interval: number): void { - // gateway.debug("GW HEARTBEATING_STARTED", { shardId, interval }); + // If old heartbeast exist like after resume, clear the old ones. + if (this.heart.intervalId) clearInterval(this.heart.intervalId) + if (this.heart.timeoutId) clearTimeout(this.heart.timeoutId) this.heart.interval = interval