Open VeskeR opened 6 months ago
This comment from ably react-hooks repo might be slightly related: https://github.com/ably-labs/react-hooks/issues/8#issuecomment-1701793139, user saw his "max connections" linearly increase (just as we did in this issue) when ably-js was run on the server during SSR
This may be related to vercel/edge-runtime#983 as that bug is also caused by a heartbeat and also results in a null object being delivered to the message handler.
When using an
Ably.Realtime
instance in the Vercel Edge runtime (to avoid https://github.com/ably/ably-js/issues/1732 error replacesetImmediate
calls in ably-js withsetTimeout
) - whether within serverless functions or in SSR when rendering the frontend in Edge runtime - the connection to Ably servers sets up correctly. However, we begin to getTypeError: Cannot read properties of null (reading 'length')
errors continuously after the connection has been set up. Here's the full error log:It is coming from the
WebSocketTransport.onWsData
method at this line. Here,data
parameter unexpectedly isnull
, causing an error. Judging by the frequency of errors above, it is highly likely that this error occurs whenever we receive an{"action":0}
heartbeat message from the server.After some time, we encounter the next error:
Transport.onIdleTimerExpire()
is triggered because we haven't observed any activity on the opened connection for the maximum idle interval. This is due to the failure of processing the heartbeat.The above issues are accompanied by the following strange behavior:
Ably.Realtime
instance running in the Vercel Edge runtime.Transport.onIdleTimerExpire()
process, and previous connections are not immediately closed. Consequently, this results in theAbly.Realtime
instance continuously opening new connections to Ably servers and eventually exhausting the maximum connection pool per account. This is the most critical problem in this issue, preventing us from allowing customers to use theAbly.Realtime
instance in the Vercel Edge runtime at the moment.┆Issue is synchronized with this Jira Task by Unito