Skip to content

Handle WebSocket close and reconnect in WebSocketProvider #4976

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Dustin4444
Copy link

@Dustin4444 Dustin4444 commented Apr 10, 2025

Fixes #1053

Implement WebSocket reconnection and keep-alive mechanism in WebSocketProvider.

  • Add onclose, onping, and onpong event handlers to handle WebSocket close events and maintain connection.
  • Utilize the #connect method for reconnection purposes.
  • Add logic to re-establish subscriptions and pending requests on reconnection.
  • Include a keep-alive mechanism with ping-pong to maintain the WebSocket connection.
  • Modify src.ts/providers/provider-websocket.ts and lib.esm/providers/provider-websocket.js to reflect these changes.

For more details, open the Copilot Workspace session.

Fixes ethers-io#1053

Implement WebSocket reconnection and keep-alive mechanism in `WebSocketProvider`.

* Add `onclose`, `onping`, and `onpong` event handlers to handle WebSocket close events and maintain connection.
* Utilize the `#connect` method for reconnection purposes.
* Add logic to re-establish subscriptions and pending requests on reconnection.
* Include a keep-alive mechanism with ping-pong to maintain the WebSocket connection.
* Modify `src.ts/providers/provider-websocket.ts` and `lib.esm/providers/provider-websocket.js` to reflect these changes.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/ethers-io/ethers.js/issues/1053?shareId=XXXX-XXXX-XXXX-XXXX).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebSocketProvider handle ws close and reconnect
1 participant