We are receiving stocks data from UDP socket and then replay it to browsers using Tornado socket connections.
However facing below error once in a while it's trying to send the same. What could be causing the same?
12346 ERROR:2018-08-24 01:01:59,202:get_broadcast
12347 Traceback (most recent call last):
12348 File "/release/manik/muTrade-1.0.0-1.7.4.5/web/utrade/WebSocket/get_broadcast.py", line 321, in _send_msg_to_clients
12349 socketConnectionObject.send(smart_str(simplejson.dumps(data)))
12350 File "/release/st01/py3Env/lib/python3.6/site-packages/sockjs/tornado/conn.py", line 49, in send
12351 self.session.send_message(message, binary=binary)
12352 File "/release/st01/py3Env/lib/python3.6/site-packages/sockjs/tornado/session.py", line 322, in send_message
12353 self.send_jsonified(proto.json_encode(bytes_to_str(msg)), stats)
12354 File "/release/st01/py3Env/lib/python3.6/site-packages/sockjs/tornado/session.py", line 337, in send_jsonified
12355 self.handler.send_pack('a[%s]' % msg)
12356 File "/release/st01/py3Env/lib/python3.6/site-packages/sockjs/tornado/transports/websocket.py", line 86, in send_pack
12357 self.write_message(message, binary)
12358 File "/release/st01/py3Env/lib/python3.6/site-packages/tornado/websocket.py", line 252, in write_message
12359 return self.ws_connection.write_message(message, binary=binary)
12360 File "/release/st01/py3Env/lib/python3.6/site-packages/tornado/websocket.py", line 783, in write_message
12361 message = self._compressor.compress(message)
12362 File "/release/st01/py3Env/lib/python3.6/site-packages/tornado/websocket.py", line 548, in compress
12363 assert data.endswith(b'\x00\x00\xff\xff')
12364 AssertionError
Edit:
Also many other errors being received, details are in this [thread][1]
This was being caused due to multiple threads. I store socketclientobjects (made when new connection is made with the tornado) in a list and use them in other threads to send the messages.
I removed socketObject.send(simplejson.dumps(msg))
which was called directly inside threads to
tornado.ioloop.IOLoop.current().add_callback( socketObject.send, simplejson.dumps(msg))
and things started working fine. I was receiving multiple errors, all got resolved.