From 4c2c2d0fff454a9e320da2bdbaa17c17229e48ef Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 6 Jul 2016 12:05:14 -0700 Subject: [PATCH] Also close the socket on receive backpressure --- daphne/ws_protocol.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/daphne/ws_protocol.py b/daphne/ws_protocol.py index a85652b..cef47ae 100755 --- a/daphne/ws_protocol.py +++ b/daphne/ws_protocol.py @@ -100,7 +100,7 @@ class WebSocketProtocol(WebSocketServerProtocol): # You have to consume websocket.connect according to the spec, # so drop the connection. self.muted = True - logger.warn("WebSocket force closed for %s due to backpressure", self.reply_channel) + logger.warn("WebSocket force closed for %s due to connect backpressure", self.reply_channel) # Send code 1013 "try again later" with close. self.sendClose(code=1013) else: @@ -132,9 +132,12 @@ class WebSocketProtocol(WebSocketServerProtocol): "text": payload.decode("utf8"), }) except self.channel_layer.ChannelFull: - # We don't drop the connection here as you don't _have_ to consume websocket.receive - # TODO: Maybe add an option to drop if this is backlogged? - pass + # You have to consume websocket.receive according to the spec, + # so drop the connection. + self.muted = True + logger.warn("WebSocket force closed for %s due to receive backpressure", self.reply_channel) + # Send code 1013 "try again later" with close. + self.sendClose(code=1013) def serverSend(self, content, binary=False): """