fix(WebSocketManager#connect): check if we have enough sessions (#8481)

* fix(WebSocketManager#connect): check if we have enough sessions

* fix: more useful error message

* fix: tests

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
DD
2022-08-16 18:28:01 +03:00
committed by GitHub
parent ebaf158006
commit 4fd42528fe
2 changed files with 38 additions and 0 deletions

View File

@@ -271,6 +271,16 @@ export class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {
public async connect() {
const shardCount = await this.getShardCount();
const data = await this.fetchGatewayInformation();
if (data.session_start_limit.remaining < shardCount) {
throw new Error(
`Not enough sessions remaining to spawn ${shardCount} shards; only ${
data.session_start_limit.remaining
} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`,
);
}
// First, make sure all our shards are spawned
await this.updateShardCount(shardCount);
await this.strategy.connect();