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

97 views
Skip to first unread message

Victor Porton

unread,
May 12, 2017, 1:52:51 PM5/12/17
to Django developers (Contributions to Django itself)

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

Andrew Godwin

unread,
May 12, 2017, 1:56:25 PM5/12/17
to Django developers (Contributions to Django itself)
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

--
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 django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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 all
Reply to author
Forward
0 new messages