Quantcast

Need to set socket options, for no breaking after a timeout

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Need to set socket options, for no breaking after a timeout

Victor Porton
About https://github.com/django/channels

In the past I dealt with another Python WebSocket engine (unrelated to Django). The connection was breaking after a timeout. I solved this problem adding:

sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 150)

sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, 150)


in the connection handler.


I strongly suspect that this is also needed for proper working of Django Channels.


Where can I hook this code up? (Where can I get the underlying Unix socket?)


Also probably these three sock.setsockopt calls should be added into the default constructor for a WebSocket. What do you think? We can provide a boolean argument, which when set to the non-default value would eliminate these extra calls. When it set to default value, should call these three sock.setsockopt (it should be the default, because breaking WS after a timeout is usually bad).

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/df05a571-7ca1-4e0c-9bfe-6c7721a3285c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need to set socket options, for no breaking after a timeout

Andrew Godwin-3
Hi Victor,

Socket handling for the TCP sockets is done by Twisted inside its TCP core, so you would have to look there to see what sort of options they set when opening a HTTP/WS connection handler. I personally have not seen too many issues with WebSocket timeouts, presumably as Daphne implements the WebSocket PING protocol to keep data flowing down the socket at regular intervals.

Andrew

On Fri, May 12, 2017 at 10:52 AM, Victor Porton <[hidden email]> wrote:

In the past I dealt with another Python WebSocket engine (unrelated to Django). The connection was breaking after a timeout. I solved this problem adding:

sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 150)

sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, 150)


in the connection handler.


I strongly suspect that this is also needed for proper working of Django Channels.


Where can I hook this code up? (Where can I get the underlying Unix socket?)


Also probably these three sock.setsockopt calls should be added into the default constructor for a WebSocket. What do you think? We can provide a boolean argument, which when set to the non-default value would eliminate these extra calls. When it set to default value, should call these three sock.setsockopt (it should be the default, because breaking WS after a timeout is usually bad).

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/df05a571-7ca1-4e0c-9bfe-6c7721a3285c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAFwN1urf7ScxjnHFCzx8%2BjahKd_SokVB%2BiCWG9L1s7ongWt13w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...