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

Fix duplicate chat connection id crash #154

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class Networked3dWebExperienceClient {
this.networkChat = new ChatNetworkingClient({
url: this.config.chatNetworkAddress,
sessionToken: this.config.sessionToken,
websocketFactory: (url: string) => new WebSocket(`${url}?id=${this.clientId}`),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive-by cleanup

websocketFactory: (url: string) => new WebSocket(url),
statusUpdateCallback: (status: WebsocketStatus) => {
if (status === WebsocketStatus.Disconnected || status === WebsocketStatus.Reconnecting) {
// The connection was lost after being established - the connection may be re-established with a different client ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ export class ChatNetworkingServer {
return;
}
if (this.clientsById.has(authResponse.id)) {
throw new Error(`Client already connected with ID: ${authResponse.id}`);
/*
This client is already connected. Reject the connection. If the old connection is abandoned then it will
be removed and retry attempts will succeed.
*/
console.error(`Client already connected with ID: ${authResponse.id}`);
socket.close();
return;
}
client.id = authResponse.id;
this.clientsById.set(client.id, client);
Expand Down
Loading