Faye detect network interruption

69 views
Skip to first unread message

Martin Konecny

unread,
Feb 14, 2018, 6:04:08 PM2/14/18
to Faye users
According to the documentation:

> ping - (optional) how often, in seconds, to send keep-alive ping messages over WebSocket and EventSource connections. Use this if your Faye server will be accessed through a proxy that kills idle connections.

Does an increased ping frequency also increase how fast Faye detects a network interruption (and therefore the need to reconnect)?

Also, not sure how ping is related to the description of timeout in the docs. Is a ping from the server included in "data the server sends"? :

> timeout - You can optionally specify a timeout; if the server does not send back any data for the given period of time, the client will assume the server has gone away and will attempt to reconnect:

I guess what Im asking is, how do I ensure no more than 5 seconds passes before faye realizes the network is down and attempts a reconnect?

 

James Coglan

unread,
Feb 19, 2018, 3:50:01 PM2/19/18
to faye-...@googlegroups.com
On 14 February 2018 at 23:04, Martin Konecny <martin....@gmail.com> wrote:
According to the documentation:

> ping - (optional) how often, in seconds, to send keep-alive ping messages over WebSocket and EventSource connections. Use this if your Faye server will be accessed through a proxy that kills idle connections.

Does an increased ping frequency also increase how fast Faye detects a network interruption (and therefore the need to reconnect)?

No, and my apologies that this is unclear.

There are two layers at work here: the transport layer (WebSocket, EventSource or regular HTTP requests) and the Bayeux layer, which is the messaging protocol that's tunnelled over the transport layer.

Pings are a transport-layer feature. WebSocket allows "ping" frames to be sent, and these are different from "message" frames. They allow the client/server handling the connection to check the other peer is responsive and the intervening network (TCP downwards) has not cut them off. They don't show up as message events in the browser WebSocket client, they're handled invisibly by the browser WebSocket implementation. The server just sends pings to the browser, and the browser (not user JS code) handles them.

Faye detects network interruption in a transport-independent manner, by either detecting those transport-layer errors that can be explicitly detected in the browser (e.g. Websocket disconnection, HTTP request failure), or by detecting timeouts in the Bayeux layer when the server doesn't acknowledge the client's messages quickly enough.

So, pings are just about keeping the transport/network layer alive and do not affect the client's Bayeux-layer error detection at all.

 
Also, not sure how ping is related to the description of timeout in the docs. Is a ping from the server included in "data the server sends"? :

> timeout - You can optionally specify a timeout; if the server does not send back any data for the given period of time, the client will assume the server has gone away and will attempt to reconnect:

I guess what Im asking is, how do I ensure no more than 5 seconds passes before faye realizes the network is down and attempts a reconnect?

The timeout is a setting that relates to the mechanics of the Bayeux protocol. The client polls for new messages by sending a message to the channel /meta/connect, regardless of which transport you're using. The server responses to this message either when there is new data to deliver to the client, or after `timeout` seconds, whichever is sooner. (If you're using WebSocket, some stuff is done to make messages push immediately to the client without interrupting the polling loop, so /meta/connect is just used as a heartbeat mechanism.)

So `timeout` defines how long the server waits before sending a reply to the client saying "sorry, no new messages right now, please poll again". It affects the Faye implementation in two ways:

- If the server does not receive a /meta/connect from a client within `2 * timeout` of the previous one, it times the client's session out
- If the client does not receive a server reply to any message within `1.2 * timeout` it considers the message failed and queues it for retrying; in this event it may emit a 'transport:down' event

I would not recommend setting things up so that Faye reports a network disconnection within 5 seconds. It's too short a time to allow things to succeed on the web, particularly over unreliable wifi and mobile connections. If you set the timeout to this short a time, you may as well implement a polling protocol, since Faye will degrade to that when used over a slow network with a short timeout. It may also result in more errors, as messages are send successfully but the response takes too long to arrive, and the transport layer will begin reporting things are errors that are actually just network latency.

If you really do want an error reported after 5 seconds, then set timeout to 4.2 seconds. However, I strongly recommend you don't do that.

ALS

unread,
Mar 27, 2018, 4:02:52 PM3/27/18
to Faye users
Hi James,

How to check ping frequency and what should be the default value for cluster environment?

Thanks
ALS
Reply all
Reply to author
Forward
0 new messages