[erlang-questions] Awkward timeout behavior in Cowboy Websockets

Noah Silverman noah@REDACTED
Wed Nov 14 03:09:46 CET 2018


Hello,

When using Cowboy Websockets, I am seeing strange behavior during a timeout.

As per the documentation, when upgrading a connection to websocket, there is an optional parameter for idle_timeout (defaults to 60000).  This works, and the connection does close after the correct number of seconds.

However, there is no timeout message sent to the client, and I don't see a way to send one.

There is a websocket_terminate/3 callback.  However, the documentation seems to indicate that function is called *after* the connection is closed.

Looking in the source code for cowboy_websocket.erl, I see on lines 417-429 the different ways to close the socket.  A "stop" and a "timeout" are handled exactly the same, with a generic close of 1000.  So, no way for the client to know that idle_timeout was triggered.

We have a service that streams data to a browser client.
- The browser connects and requests a subscriptions to a feed
- We then stream that data continuously.
- No further action is required from the client, except a ping to keep the connection open.

However, if the client doesn't ping, the connection will close silently.  There is no indication to the client that they were dropped due to timeout.

Is there a way to remedy this?  Perhaps some way to have Cowboy send a "timeout message" when idle_timeout triggers?

Thank You,

--
Noah
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181114/e281c540/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: publickey - noah@REDACTED - 0xBCEFA873.asc
Type: application/pgp-keys
Size: 3136 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181114/e281c540/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 855 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181114/e281c540/attachment-0001.bin>


More information about the erlang-questions mailing list