How to maintain healthy ws connection?

Our platform is experiencing repeated closes of connections for no reason
We monitor 65 matches channels over a 4 ws connections.
The 4th one only have 3 pairs, not a lot of activity that’s for sure
It just keeps disconnecting every few minutes :

We are using the following endpoint : wss://ws-feed.pro.coinbase.com
And for subscriptions :

{
  type: 'subscribe',
  channels: [{ name: 'matches', product_ids: [pair] }],
}

I see theres no ping pong messages on your api so how to we ensure the connection remain alive and well for the longest time possible ?

Thank you :grinning:

Hi @tucsky ! We understand that you have set up a Websocket connection and subscribed to a user channel but are getting disconnected after receiving initial messages. We also understand that you are looking for any keep_alive mechanism or its equivalent that could work for the Websocket channel so that this scenario of being disconnected from the channel is prevented. However, we regret to inform you that such a feature/mechanism is not yet available with the Websocket. As a workaround for now, we suggest that you try adding an implementation within your code that will automatically reconnect your Websocket upon disconnecting. Disconnects are normal with Websockets and are sometimes even forced by us when deploying updates. Also, you may consider increasing the timeout window for the library or stack you are using.

Additionally, we also suggest you to avoid having the Websocket connection being established over the public internet as this may also cause intermittent network connection and also cause latency delay in delivering update messages over the channel or being disconnected from it. You can check out this section to know more about the best practices when utilizing Websocket channels.

Lastly, we would like to inform you that we have logged this as a feedback with our internal teams so we can continue improving our user experience. Most new features and improvements to our products come directly from feedback like yours, so it’s very valuable to us. While we can’t offer any specific timeline for adding features, we are constantly working to build products our customers will love. And if you want to stay up to date on the latest from Coinbase Cloud, you can also bookmark the following webpage and subscribe to email updates at the bottom of the page: https://www.coinbase.com/cloud/discover

We hope this is helpful, and please let us know if you have any other questions. Have a nice day!

1 Like

@Anonymouse I think you guys should add a ping/pong frame. It’s pretty standard way to do it nowadays :grinning:

2 Likes

Hello @tucsky! We hear your suggestion on adding a ping/pong frame to ensure a healthy websocket connection, rest assured that we’ve logged this as a feature request with our internal teams so we can continue improving our user experience. Most new features and improvements to our products come directly from feedback like yours, so it’s very valuable to us. While we can’t offer any specific timeline for adding features, we are constantly working to build products our customers will love.

If you want to stay up to date on the latest from Coinbase Cloud, you can also bookmark the following webpage and subscribe to email updates at the bottom of the page: https://www.coinbase.com/cloud/discover

We really appreciate you for bringing this up to our attention, thank you!

2 Likes

I was having several disconnects per day. Then I spent the month of January trying to fix it and came up with the following strategy which has been working since January persistent with no drops. I am using PHP Websocket class, so yours may no be the same:

  1. Make sure you increase your websocket timeout to something like 60 seconds
  2. Wrap your websocket client receives in try catch block
  3. If receive throws timeout just receive again
  4. If receive throws EOF then your websocket is gone and you have to re-create the connection and continue

Just for additional context here: Coinbase Exchange offers two Websocket endpoints (highlighted at the top of this page).

The Coinbase Direct Market Data (ws-direct.exchange.coinbase.com) offering requires users to authenticate in order to receive data, however; it will bypass the Cloudflare infrastructure that the Coinbase Market Data (ws-feed.exchange.coinbase.com) offering uses.

Subscribers have reported significantly less abrupt disconnects and lower latency using the Coinbase Direct Market Data offering, so this is something to consider if it fits your use case.