socketIO-client
socketIO-client copied to clipboard
Connecting to secondary namespace hangs on recv
Similar to https://github.com/invisibleroads/socketIO-client/issues/117 but hanging later on "recv".
When running the code below the connection hangs during definition of the namespace.
If I comment out the "define" namespace line and use the root namespace for emitting all works fine and it does not hang.
Server code
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# vim: expandtab shiftwidth=4 softtabstop=4
#
from flask import Flask, json, g, session
from flask_socketio import SocketIO
import logging
app = Flask(__name__)
app.config['SECRET_KEY'] = 'somethingsomething'
socketio = SocketIO(app)
@socketio.on('connect')
def connect():
logging.debug('connect on root namespace')
@socketio.on('connect', namespace='/devices')
def connect_odometer():
logging.debug('connect on /devices namespace')
@socketio.on('test', namespace='/devices')
def test():
logging.debug('received test')
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
socketio.run(app)
Client code
# -*- coding: utf-8 -*-
#
# vim: expandtab shiftwidth=4 softtabstop=4
#
import logging
from socketIO_client import SocketIO, BaseNamespace
class TestNamespace(BaseNamespace):
def on_connect(self):
logger = logging.getLogger('application.push_service')
logger.debug('connected')
def on_disconnect(self):
logger = logging.getLogger('application.push_service')
logger.debug('disconnected')
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
connection = SocketIO('localhost', 5000)
ns = connection.define(TestNamespace, '/devices')
ns.emit('test')
print('end!')
Server output
We can see that it is indeed connecting to both root and "/devices" namespaces:
DEBUG:geventwebsocket.handler:Initializing WebSocket
DEBUG:geventwebsocket.handler:Validating WebSocket request
DEBUG:root:connect on root namespace
INFO:geventwebsocket.handler:127.0.0.1 - - [2018-04-01 08:24:40] "GET /socket.io/?EIO=3&transport=polling&t=1522563880071-0 HTTP/1.1" 200 357 0.000771
DEBUG:geventwebsocket.handler:Initializing WebSocket
DEBUG:geventwebsocket.handler:Validating WebSocket request
DEBUG:geventwebsocket.handler:Attempting to upgrade connection
DEBUG:geventwebsocket.handler:WebSocket request accepted, switching protocols
DEBUG:geventwebsocket.handler:Failed to write closing frame -> closing socket
DEBUG:geventwebsocket.handler:Closed WebSocket
DEBUG:root:connect on /devices namespace
Client output
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost
DEBUG:urllib3.connectionpool:http://localhost:5000 "GET /socket.io/?EIO=3&transport=polling&t=1522563880071-0 HTTP/1.1" 200 119
DEBUG:socketIO-client-2:localhost:5000/socket.io [transport selected] websocket
DEBUG:socketIO-client-2:localhost:5000/socket.io [heartbeat reset]
DEBUG:socketIO-client-2:localhost:5000/socket.io [socket.io packet sent] 0/devices,
DEBUG:socketIO-client-2:localhost:5000/socket.io [socket.io packet received] b'0/devices'
DEBUG:application.push_service:connected
It hangs here and doesn't continue.
Client stack
After interrupting it reveals that it hangs in recv:
^CTraceback (most recent call last):
File "./push_service.py", line 21, in <module>
ns = connection.define(TestNamespace, '/devices')
File "/usr/lib/python3.6/site-packages/socketIO_client/__init__.py", line 373, in define
self.wait(for_connect=True)
File "/usr/lib/python3.6/site-packages/socketIO_client/__init__.py", line 245, in wait
self._process_packets()
File "/usr/lib/python3.6/site-packages/socketIO_client/__init__.py", line 267, in _process_packets
for engineIO_packet in self._transport.recv_packet():
File "/usr/lib/python3.6/site-packages/socketIO_client/transports.py", line 156, in recv_packet
packet_text = self._connection.recv()
File "/usr/lib/python3.6/site-packages/websocket/_core.py", line 300, in recv
opcode, data = self.recv_data()
File "/usr/lib/python3.6/site-packages/websocket/_core.py", line 317, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/usr/lib/python3.6/site-packages/websocket/_core.py", line 330, in recv_data_frame
frame = self.recv_frame()
File "/usr/lib/python3.6/site-packages/websocket/_core.py", line 364, in recv_frame
return self.frame_buffer.recv_frame()
File "/usr/lib/python3.6/site-packages/websocket/_abnf.py", line 361, in recv_frame
self.recv_header()
File "/usr/lib/python3.6/site-packages/websocket/_abnf.py", line 309, in recv_header
header = self.recv_strict(2)
File "/usr/lib/python3.6/site-packages/websocket/_abnf.py", line 396, in recv_strict
bytes_ = self.recv(min(16384, shortage))
File "/usr/lib/python3.6/site-packages/websocket/_core.py", line 434, in _recv
return recv(self.sock, bufsize)
File "/usr/lib/python3.6/site-packages/websocket/_socket.py", line 81, in recv
bytes_ = sock.recv(bufsize)
KeyboardInterrupt
Server virtualenv
click (6.7) Flask (0.12.2) Flask-SocketIO (2.9.6) gevent (1.2.2) gevent-websocket (0.10.1) greenlet (0.4.13) itsdangerous (0.24) Jinja2 (2.10) MarkupSafe (1.0) pip (9.0.1) python-engineio (2.0.4) python-socketio (1.9.0) setuptools (28.8.0) six (1.11.0) Werkzeug (0.14.1)
requirements.txt:
Flask>=0.12.2
Flask-SocketIO>=2.9.6
gevent>=1.2.2
gevent-websocket>=0.10.1
Client virtualenv
certifi (2018.1.18) chardet (3.0.4) idna (2.6) pip (9.0.1) requests (2.18.4) setuptools (28.8.0) six (1.11.0) socketIO-client-2 (0.7.5) urllib3 (1.22) websocket-client (0.47.0)
Requirements.txt:
socketIO-client-2>=0.7.5
More env info
python3-3.6.4-6.1.x86_64 openSUSE Tumbleweed 20180314 Kernel 4.15.8-1-default