-
Notifications
You must be signed in to change notification settings - Fork 306
feat(lazer): Improve JS SDK reliability via redundant parallel websocket cxns #2236
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
| addSubscription(request: Request) { | ||
| if (request.type !== "subscribe") { | ||
| throw new Error("Request must be a subscribe request"); | ||
| } | ||
| this.subscriptions.set(request.subscriptionId, request); | ||
| this.sendRequest(request); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to listen for subscribed response here and throw an error if it was not successful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should improve the server side error handling for sure
| removeSubscription(subscriptionId: number) { | ||
| this.subscriptions.delete(subscriptionId); | ||
| const request: Request = { | ||
| type: "unsubscribe", | ||
| subscriptionId, | ||
| }; | ||
| this.sendRequest(request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here

Purpose
Improve JS SDK reliability via redundant parallel websocket connections (default of 3.) This reduces the chance of dropped messages during reconnection events, since other websockets will be receiving the otherwise missed messages. The parallel streams are merged and deduped to provide a single reliable stream to the SDK user.
Try it out by running
pnpm run example(examples/index.ts)Technical details
PythLazerClientis a thin wrapper aroundWebSocketPoolwhich provides some convenient parsing on the received messages.Introduced
WebSocketPool, which handles resilience at the pool level.ReliableWebSocketinstances, and provides usage semantics similar to a single standard WebSocket so that users don't have to deal with the details of managing multiple connections.sendcommands to all sockets in the pool for un/subscribing.Reused and adapted
ReliableWebSocketto handle resilience at the individual connection level.openmessage before sending messages. However, this hasn't been an issue in practice when testing manually.Testing
Tested manually successfully with up to 50 parallel connections. Reconnections are handled cleanly and no duplicate messages are delivered.