Skip to content
Permalink
Browse files

[WIP] Issue #261: do not loose first websocket message due to race co…

…ndition
  • Loading branch information...
spaceone committed Jan 24, 2019
1 parent 7fea2d0 commit 9d3df4b5e6ecbc14a7a26dd0053ad073066ed63e
Showing with 11 additions and 1 deletion.
  1. +11 −1 circuits/web/websockets/client.py
@@ -55,6 +55,7 @@ def __init__(self, url, channel=channel, wschannel="ws", headers=None):
self._response = None
self._pending = 0
self._wschannel = wschannel
self._codec = None

self._transport = TCPClient(channel=self.channel).register(self)
HTTP(channel=self.channel).register(self._transport)
@@ -109,9 +110,18 @@ def _on_response(self, response):
or response.status != 101:
self.fire(close(), self._transport)
raise NotConnected()
WebSocketCodec(
self._codec = WebSocketCodec(
data=response.body.read(), channel=self._wschannel).register(self)

@handler('read')
def _on_read(self, event, *args):
if len(args) != 1:
return
if self._codec and self._codec.parent is self:
if 'read' not in self._codec.events():
event.stop()
self.fire(event.create('read', *args))

@handler("error", priority=10)
def _on_error(self, event, error, *args, **kwargs):
# For HTTP 1.1 we leave the connection open. If the peer closes

0 comments on commit 9d3df4b

Please sign in to comment.
You can’t perform that action at this time.