noisyboiler / wampy

Websocket RPC and Pub/Sub for Python applications and microservices
Mozilla Public License 2.0
127 stars 24 forks source link

ping handling #50

Closed fnordian closed 6 years ago

fnordian commented 6 years ago

Hi!

Creating and starting a long running client leads to disconnects due to unhandled pings from the router.

with wampy.Client(url="ws://localhost:8080/ws") as client:
    client.publish(topic="test", foo="bar")
    time.sleep(10)
    client.publish(topic="test", foo="bar")
 Traceback (most recent call last):
  File "/home/marcus/local/python/python3env/lib/python3.6/site-packages/wampy/transports/websocket/frames.py", line 253, in __init__
    self.payload = json.loads(self.body.decode('utf-8'))
  File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.6/json/decoder.py", line 342, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 2 (char 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/marcus/local/python/python3env/lib/python3.6/site-packages/eventlet/hubs/poll.py", line 114, in wait
    listener.cb(fileno)
  File "/home/marcus/local/python/python3env/lib/python3.6/site-packages/eventlet/greenthread.py", line 218, in main
    result = function(*args, **kwargs)
  File "/home/marcus/local/python/python3env/lib/python3.6/site-packages/wampy/session.py", line 158, in connection_handler
    frame = connection.receive()
  File "/home/marcus/local/python/python3env/lib/python3.6/site-packages/wampy/transports/websocket/connection.py", line 86, in receive
    frame = ServerFrame(received_bytes)
  File "/home/marcus/local/python/python3env/lib/python3.6/site-packages/wampy/transports/websocket/frames.py", line 256, in __init__
    'Failed to load JSON object from: "%s"', self.body
wampy.errors.WebsocktProtocolError: ('Failed to load JSON object from: "%s"', bytearray(b'6xLI'))
Removing descriptor: 3

Are there plans to add ping-handling?

fnordian commented 6 years ago

Please consider merging https://github.com/noisyboiler/wampy/pull/51

noisyboiler commented 6 years ago

Thanks for this @fnordian Is this similar to the heartbeat in AMQP? I wasn't aware of the pings from the router.

fnordian commented 6 years ago

They seem to have the same intention. But I am not familiar with the amqp protocol. In the wamp-case, detection of stale tcp-connections happens in the websocket-layer, not the wamp-layer.

noisyboiler commented 6 years ago

sorted. see https://github.com/noisyboiler/wampy/pull/51

noisyboiler commented 6 years ago

see https://github.com/noisyboiler/wampy/releases/tag/0.9.13 thanks @fnordian

fnordian commented 6 years ago

Cool. You're welcome.