Skip to content

Commit

Permalink
fix(WebSocketShard): #send race condition due to ready state (#9226)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
didinele and kodiakhq[bot] committed Mar 12, 2023
1 parent 6ecff26 commit a99fc64
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/ws/src/ws/WebSocketShard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,9 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
d,
});

const { ok } = await this.bubbleWaitForEventError(
await this.bubbleWaitForEventError(
this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout),
);
if (!ok) {
return;
}

this.#status = WebSocketShardStatus.Ready;
}

private async resume(session: SessionInfo) {
Expand Down Expand Up @@ -499,7 +494,7 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
// eslint-disable-next-line sonarjs/no-nested-switch
switch (payload.t) {
case GatewayDispatchEvents.Ready: {
this.emit(WebSocketShardEvents.Ready, { data: payload.d });
this.#status = WebSocketShardStatus.Ready;

this.session ??= {
sequence: payload.s,
Expand All @@ -510,6 +505,8 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
};

await this.strategy.updateSessionInfo(this.id, this.session);

this.emit(WebSocketShardEvents.Ready, { data: payload.d });
break;
}

Expand Down

2 comments on commit a99fc64

@vercel
Copy link

@vercel vercel bot commented on a99fc64 Mar 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on a99fc64 Mar 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.