solana icon indicating copy to clipboard operation
solana copied to clipboard

Would you support the "pong" response in websocket api when receiving "ping"?

Open yihau opened this issue 4 years ago • 6 comments

Problem

I connect to my own solana node via websocket, but I found It seems not provide a complete heartbeat flow (send ping then get pong). imho, a pong not only a server response, also a network performance. I can know there is something wrong via a late response time.

Proposed Solution

Just like other api do, response a struct {"jsonrpc":"2.0","result":"pong","id": 1} or something like that.

yihau avatar Feb 08 '21 16:02 yihau

Interesting. Do you have an example of an existing API that does this?

mvines avatar Feb 08 '21 16:02 mvines

I think It is similar. https://huobiapi.github.io/docs/spot/v1/en/#introduction-12 Although the ping/pong flow direction is inverse, the main idea is the same, checking the heartbeat.

yihau avatar Feb 08 '21 16:02 yihau

Got it, yes that seems nice to have

mvines avatar Feb 08 '21 16:02 mvines

I'd like to say that, from our point of view, it's not just a nice to have. Getting a heartbeat response every n seconds is quite useful to know the connection is still alive, we're running into this issue right now where a websocket seems to silently stop giving updates after a few hours. The feedback loop to find out when it dies it very slow, it seems nondeterministic, it takes a whole day to find out that it stopped working. Not sure if it's due to tokio or due to solana, but a guarantee from solana would help a lot.

y2kappa avatar Oct 13 '21 11:10 y2kappa

@mvines , is there any update around this issue or for the above comment?

I've personally noticed packets exchanged on the socket at regular time intervals, which looked like ping/pong messages, but I double on the above comment because the unreliability of the socket connection can be seen especially over time (hours or couple of days really). Even manual testing resulted in missed notifications from the network (worked mainly with the Connection::onLogs method of solana-web3js on top of devnet cluster). Having guides for reliable usage over time of the websockets API would be helpful, or notes on the production readiness of this feature and how to be successful in using it. Not an easy task probably, but the general idea is that the poor support and efficiency around the websocket API became the basis right now and from my research on the topic, it is seen as a notoriously unreliable thing to use.

LE: the problem can also be client related but it seems, at least from my code reading, that solana-web3js tries to auto-reconnect for implicit socket close (https://github.com/solana-labs/solana-web3.js/blob/50473697a7f8f80d06532f06d79677d54a0df6e4/src/connection.ts#L4293).

Also @y2kappa , curious if you've reached a reliable setup while working with websockets API or if there are other alternatives you've employed.

iulianbarbu avatar Jun 16 '22 11:06 iulianbarbu

hey, I want to take this problem. As far as I understand, do we need to add $ solana ping command to the CLI tool? @iulianbarbu @y2kappa @yihau would help if you could provide more info on it

kubanemil avatar Apr 14 '24 09:04 kubanemil