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

Reconnect L1 WS stream if disconnected #2287

Merged
merged 3 commits into from
Nov 18, 2024
Merged

Reconnect L1 WS stream if disconnected #2287

merged 3 commits into from
Nov 18, 2024

Conversation

jbearer
Copy link
Member

@jbearer jbearer commented Nov 15, 2024

Ethers internally tries to reconnect once, but if that fails, it gives up and shuts down the whole provider backend. This is not good in the case of extended outages of the L1 server.

This PR:

  • handles errors from the underlying RPC client indicating that the connection is closed by spawning a task to reestablish the connection. This task tries until it succeeds

Key places to review:

  • Reconnect logic: RpcClient::request
  • Cancellation logic: RpcClient::drop, L1Client::stop

Things tested

New regression tests fail before this change

})
}

async fn stop(&self) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this only stops the reconnect functionality, but the L1 connection is still reachable. Maybe it should be renamed to something more appropriate

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it stops all the background tasks (the reconnect task and the snapshot updating task). Ideally this would take self by value and just destroy the whole client but it's not easy to implement like that because L1 client is behind an Arc in NodeState.

Maybe like shut_down_tasks, and also rename start to spawn_tasks?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me

@imabdulbasit imabdulbasit self-requested a review November 18, 2024 17:48
Ethers internally tries to reconnect once, but if that fails, it
gives up and shuts down the whole provider backend. This is not
good in the case of extended outages of the L1 server.

This change handles errors from the underlying RPC client indicating
that the connection is closed by spawning a task to reestablish the
connection. This task tries until it succceeds.
@jbearer jbearer merged commit 5ad4da1 into main Nov 18, 2024
19 checks passed
@jbearer jbearer deleted the jb/ws-reconnect branch November 18, 2024 18:44
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.

2 participants