mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[fix] Close WebSocket on action ended to prevent unclosed and lost socket
This commit is contained in:
parent
1bc6308b3a
commit
f86cec3458
1 changed files with 24 additions and 4 deletions
|
@ -279,11 +279,23 @@ class _ActionsMapPlugin(object):
|
||||||
return HTTPErrorResponse(m18n.g('websocket_request_excepted'))
|
return HTTPErrorResponse(m18n.g('websocket_request_excepted'))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
style, message = queue.get()
|
item = queue.get()
|
||||||
try:
|
try:
|
||||||
wsock.send(json_encode({ style: message }))
|
# Retrieve the message
|
||||||
except WebSocketError:
|
style, message = item
|
||||||
break
|
except TypeError:
|
||||||
|
if item == StopIteration:
|
||||||
|
# Delete the current queue and break
|
||||||
|
del self.queues[s_id]
|
||||||
|
break
|
||||||
|
logging.warning("invalid item in the messages queue: %r" % item)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
# Send the message
|
||||||
|
wsock.send(json_encode({ style: message }))
|
||||||
|
except WebSocketError:
|
||||||
|
break
|
||||||
|
sleep(0)
|
||||||
|
|
||||||
def process(self, _route, arguments={}):
|
def process(self, _route, arguments={}):
|
||||||
"""Process the relevant action for the route
|
"""Process the relevant action for the route
|
||||||
|
@ -303,6 +315,14 @@ class _ActionsMapPlugin(object):
|
||||||
raise HTTPErrorResponse(e.strerror)
|
raise HTTPErrorResponse(e.strerror)
|
||||||
else:
|
else:
|
||||||
return ret
|
return ret
|
||||||
|
finally:
|
||||||
|
# Close opened WebSocket by putting StopIteration in the queue
|
||||||
|
try:
|
||||||
|
queue = self.queues[request.get_cookie('session.id')]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
queue.put(StopIteration)
|
||||||
|
|
||||||
|
|
||||||
## Signals handlers
|
## Signals handlers
|
||||||
|
|
Loading…
Add table
Reference in a new issue