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

Question: Disconnect ws connection from server side #1448

Closed
shunsukew opened this issue Sep 4, 2024 · 3 comments
Closed

Question: Disconnect ws connection from server side #1448

shunsukew opened this issue Sep 4, 2024 · 3 comments

Comments

@shunsukew
Copy link

shunsukew commented Sep 4, 2024

Is it possible to disconnect ws connection from server side by using jsonrpsee api?

What I'm thinking of is disconnect ws connection from server side (not from client side) under specific situations.

@shunsukew shunsukew changed the title Question: Terminate accepted subscription sink Question: Disconnect subscription sink after accepting Sep 4, 2024
@shunsukew
Copy link
Author

shunsukew commented Sep 4, 2024

As a background, software that proxying subscriptions (for e.g. Subway), proxy silently stop sending responses to clients when upstream ws connection is disconnected.

To avoid such situation, what I came up with are

  • proxy re-subscribe once upstream connection re-established.
  • Disconnect client side ws connection, and let clients to have chance to reconnect&subscribe.

@shunsukew shunsukew changed the title Question: Disconnect subscription sink after accepting Question: Disconnect ws connection from server side Sep 4, 2024
@niklasad1
Copy link
Member

niklasad1 commented Sep 5, 2024

Hey @shunsukew

Is it possible to disconnect ws connection from server side by using jsonrpsee api?

There is no dedicated API in jsonrpsee for the server-side the close down connections but it's possible to use to the low-level API with rpc middleware (which is a bit complicated to use)

There is a similar issue regarding this #1427

When talking about subscriptions specifically I just want clarify that a few options exist to inform the client without closing the connection:

  • Reject the subscription i.e, call Subscription::reject which just returns an error the origin RPC call
  • Send a special "error notification" or "application specific notification" before closing down subscription
  • Silently just drop the subscription

@shunsukew
Copy link
Author

Hello, Thank you for the information!

Reject the subscription i.e, call Subscription::reject which just returns an error the origin RPC call

I was looking for a way to disconnect after accepting.

Send a special "error notification" or "application specific notification" before closing down subscription

In our usecase, just proxying standard subscribe calls (e.g. eth_subscribe newHeads), quite hard to add custom error notification, client sdk doesn't understand it because it's not eth/substrate standards.

Thank you for the sharing low level apis! I think this is the only way to disconnect after accepting PendingSubscription.
For now, we have 2 different ws connection (client <> proxy and proxy <> upstream), and decided to re-subscribe after re-established the upstream connection, while keeping client side ws connection stay connected.
Possibly, will find a way to use those low level apis to disconnect connection itself.

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

No branches or pull requests

2 participants