websocket browser clients constantly disconnecting (and reconnecting) in 1.0.x

2,518 views
Skip to first unread message

Evan Tahler

unread,
Oct 19, 2013, 9:52:05 PM10/19/13
to faye-...@googlegroups.com
Hi!

I recently upgraded to fay 1.0.x and raye-redis 0.2.x (node).  Since the upgrade, I've noticed that websocket clients (truly using the websocket transport) always disconnect after being idle for ~1 min then reconnect.  I'm registering to the 'transport:down' and 'transport:up' events to detect this and reconnect.  This behavior seems to be only with the websocket transport, and when I disable that transport all together (client.disable('websocket');), the problem isn't present.  This behavior was not present in earlier versions of faye/faye-redis.

Anyone have any suggestions how I might debug this? 

remoe

unread,
Oct 20, 2013, 11:41:30 AM10/20/13
to faye-...@googlegroups.com
Hi

I've also issues on that:

James Coglan

unread,
Oct 21, 2013, 4:30:16 PM10/21/13
to faye-...@googlegroups.com
On 20 October 2013 02:52, Evan Tahler <evant...@gmail.com> wrote:
I recently upgraded to fay 1.0.x and raye-redis 0.2.x (node).  Since the upgrade, I've noticed that websocket clients (truly using the websocket transport) always disconnect after being idle for ~1 min then reconnect.  I'm registering to the 'transport:down' and 'transport:up' events to detect this and reconnect.  This behavior seems to be only with the websocket transport, and when I disable that transport all together (client.disable('websocket');), the problem isn't present.  This behavior was not present in earlier versions of faye/faye-redis.

Does the problem persist using the built-in in-memory engine, or only with Redis? Can you provide a small demo app that shows the problem? 

Evan Tahler

unread,
Oct 22, 2013, 1:56:20 AM10/22/13
to faye-...@googlegroups.com
OK! I've gotten to the bottom of this.  Here's a gist with my example/test application https://gist.github.com/evantahler/7095751 which I will reference below.

This problem exists with both the default in-memory engine and the redis engine.  I have an extension stubbed (here) which under certain circumstances I either didn't call the `callback()` or called-back with `callback(null)`.  I do this when clients send 'server' messages which I don't want repeated back (and the server acknowledges with a receipt message later on). 

In older versions of faye `callback(null)` was OK, but it seems that now in faye 1.0.x that callback is very important, as not receiving it cause the client to suspect a connection error (which seems pretty reasonable now that I think about it).

The question becomes: How can I write an extension which A) won't crash the client and B) won't echo the message?

To run my test app:
- npm install
- npm start
- open 2 browser tabs to http://localhost:8080/ and open the console/inspector
- prove that by default everything works OK by `say("hello")` and chat between tabs
- prove that the extension with a `callback(null)` is the culprit by `say("break")` and watching on that tab disconnect in ~1 minute after the command is sent.

Evan Tahler

unread,
Oct 22, 2013, 2:00:37 AM10/22/13
to faye-...@googlegroups.com
For the curious, here's the *real* faye extension that actionHero uses which does a `callback(null)`  https://github.com/evantahler/actionHero/blob/master/servers/websocket.js#L104-L126

Evan Tahler

unread,
Oct 25, 2013, 7:56:43 PM10/25/13
to faye-...@googlegroups.com
In the mean time, I can update my application's logic to be comfortable with an echo'd message, however I would like to know if would be possible to not echo.

Thanks! 

James Coglan

unread,
Dec 10, 2013, 5:07:09 AM12/10/13
to faye-...@googlegroups.com
On 22 October 2013 06:56, Evan Tahler <evant...@gmail.com> wrote:
This problem exists with both the default in-memory engine and the redis engine.  I have an extension stubbed (here) which under certain circumstances I either didn't call the `callback()` or called-back with `callback(null)`.  I do this when clients send 'server' messages which I don't want repeated back (and the server acknowledges with a receipt message later on). 

You should not be calling callback(null), it causes problems since if the client does not receive an acknowledgement for a message, it will retry sending it later on. If you don't want a message to be processed by the server and routed to other clients, add an 'error' property to it, or publish it to a cryptographically secure channel name negotiated with the server.

In older versions of faye `callback(null)` was OK, but it seems that now in faye 1.0.x that callback is very important, as not receiving it cause the client to suspect a connection error (which seems pretty reasonable now that I think about it).

It has never been okay, but there have been bugs in client-side error detection that means you might have been 'getting away with it'. The server MUST send an acknowledgement to the client on receipt of each message, and using callback(null) breaks this requirement.

James Coglan

unread,
Dec 10, 2013, 5:07:35 AM12/10/13
to faye-...@googlegroups.com
On 20 October 2013 16:41, remoe <remo.eic...@gmail.com> wrote:

This issue is unrelated, I'm working on fixing it. 
Reply all
Reply to author
Forward
0 new messages