Also close the socket on receive backpressure

This commit is contained in:
Andrew Godwin 2016-07-06 12:05:14 -07:00
parent ac7af23df1
commit 4c2c2d0fff

View File

@ -100,7 +100,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
# You have to consume websocket.connect according to the spec, # You have to consume websocket.connect according to the spec,
# so drop the connection. # so drop the connection.
self.muted = True 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. # Send code 1013 "try again later" with close.
self.sendClose(code=1013) self.sendClose(code=1013)
else: else:
@ -132,9 +132,12 @@ class WebSocketProtocol(WebSocketServerProtocol):
"text": payload.decode("utf8"), "text": payload.decode("utf8"),
}) })
except self.channel_layer.ChannelFull: except self.channel_layer.ChannelFull:
# We don't drop the connection here as you don't _have_ to consume websocket.receive # You have to consume websocket.receive according to the spec,
# TODO: Maybe add an option to drop if this is backlogged? # so drop the connection.
pass 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): def serverSend(self, content, binary=False):
""" """