Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(WebSocketManager): available sessions check (#9823)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
didinele and kodiakhq[bot] committed Sep 10, 2023
1 parent 6404c01 commit e68ab16
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/ws/src/ws/WebSocketManager.ts
Expand Up @@ -293,18 +293,20 @@ export class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {

public async connect() {
const shardCount = await this.getShardCount();
// Spawn shards and adjust internal state
await this.updateShardCount(shardCount);

const shardIds = await this.getShardIds();
const data = await this.fetchGatewayInformation();
if (data.session_start_limit.remaining < shardCount) {

if (data.session_start_limit.remaining < shardIds.length) {
throw new Error(
`Not enough sessions remaining to spawn ${shardCount} shards; only ${
`Not enough sessions remaining to spawn ${shardIds.length} 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();
}

Expand Down

0 comments on commit e68ab16

Please sign in to comment.