[erlang-questions] Awkward timeout behavior in Cowboy Websockets

Loïc Hoguin essen@REDACTED
Wed Nov 14 08:07:51 CET 2018

Sounds like you are using Cowboy 1.x, in which case it'll be simpler to 
fork and fix directly.

Someone mentioned not too long ago that sending 1001 for timeout closes 
might be a good idea. I'm probably OK with that, but nobody's opened a 
ticket or PR so the idea got lost in the back of my mind.


On 11/14/18 3:09 AM, Noah Silverman wrote:
> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

Loïc Hoguin

More information about the erlang-questions mailing list