Awkward timeout behavior in Cowboy Websockets

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Awkward timeout behavior in Cowboy Websockets

Noah Silverman
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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

publickey - noah@helios.ai - 0xBCEFA873.asc (4K) Download Attachment
signature.asc (875 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Awkward timeout behavior in Cowboy Websockets

Loïc Hoguin-3
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.

Cheers,

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
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Awkward timeout behavior in Cowboy Websockets

Noah Silverman
Hi Loic,

Actually using Cowboy 2.5, and following examples examples directly from the user guide on ninenines website.




--
Noah



‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Wednesday, November 14, 2018 3:07 PM, Loïc Hoguin <[hidden email]> wrote:

> 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.
>

> Cheers,
>

> 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
> > [hidden email]
> > http://erlang.org/mailman/listinfo/erlang-questions
>

> --
>

> Loïc Hoguin
> https://ninenines.eu


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

publickey - noah@helios.ai - 0xBCEFA873.asc (4K) Download Attachment
signature.asc (875 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Awkward timeout behavior in Cowboy Websockets

Loïc Hoguin-3
The websocket_terminate/3 callback was removed in 2.0 so make sure you
follow the correct documentation. :)

Anyway let's continue in a ticket.

Cheers,

On 11/14/18 12:12 PM, Noah Silverman wrote:

> Hi Loic,
>
> Actually using Cowboy 2.5, and following examples examples directly from the user guide on ninenines website.
>
>
>
>
> --
> Noah
>
>
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Wednesday, November 14, 2018 3:07 PM, Loïc Hoguin <[hidden email]> wrote:
>
>> 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.
>>
>
>> Cheers,
>>
>
>> 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
>>> [hidden email]
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
>> --
>>
>
>> Loïc Hoguin
>> https://ninenines.eu
>

--
Loïc Hoguin
https://ninenines.eu
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions