What is the appropriate way to deal with cfWebSocket timing out?

182 Views Asked by At

Some pages of our application establish a websocket connection to a channel specific to the user. Messages are published to this channel on an irregular basis (sometimes within a few seconds, sometimes not for 30-60 minutes or longer), allowing our application to communicate between browser tabs.

We have noticed that our code works as expected when tabs are first open, but after a tab has sat idle for several minutes it seems to drop the connection and does not receive any new messages published to that channel.

The odd thing is that old tabs still seem to be able to publish information. If action is taken on an old tab a new tab sees that published message. However, if action is taken on a new tab, the old one does not see it.

In our testing it seems to take somewhere between 2 and 4 minutes for this timeout to occur.

We were able to partially solve this problem by adding a 'heartbeat', by way of a javascript function that fires every 57 seconds to publish to the channel. With this heartbeat the websockets seem to last as long as several hours, but still invariably time out, and the duration has a large variation (sometimes it drops in less than an hour). We are concerned about the overhead this introduces, and while 1+ hours may be acceptable the eventual drops make this seem kludgy.

What is the appropriate way to insure websocket connections remain active and stable with minimal overhead.

0

There are 0 best solutions below