Skip to content

Commit

Permalink
More robust handling of the upgrade exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Oct 19, 2015
1 parent 79cb6b0 commit 66b4bc1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions engineio/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def _websocket_handler(self, ws):
"""Engine.IO handler for websocket transport."""
if self.connected:
# the socket was already connected, so this is an upgrade
self.queue.join() # flush the queue first

pkt = ws.wait()
if pkt != packet.Packet(packet.PING,
data=six.text_type('probe')).encode(
Expand All @@ -124,8 +126,6 @@ def _websocket_handler(self, ws):
packet.PONG,
data=six.text_type('probe')).encode(always_bytes=False))
self.send(packet.Packet(packet.NOOP))
self.upgraded = True
self.queue.join()

pkt = ws.wait()
if pkt != packet.Packet(packet.UPGRADE).encode(always_bytes=False):
Expand All @@ -134,6 +134,7 @@ def _websocket_handler(self, ws):
'%s: Failed websocket upgrade, no UPGRADE packet',
self.sid)
return
self.upgraded = True
else:
self.connected = True
self.upgraded = True
Expand Down

0 comments on commit 66b4bc1

Please sign in to comment.