Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ConnectionClosed exceptions #16

Closed
bmoscon opened this issue Mar 10, 2018 · 3 comments
Closed

Handle ConnectionClosed exceptions #16

bmoscon opened this issue Mar 10, 2018 · 3 comments
Assignees

Comments

@bmoscon
Copy link
Owner

bmoscon commented Mar 10, 2018

Websocket connections can be closed for a variety of reasons. These should be handled and the connection re-established if possible. Some tracebacks from my server:

Error in data transfer
Traceback (most recent call last):
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 496, in transfer_data
    msg = yield from self.read_message()
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 526, in read_message
    frame = yield from self.read_data_frame(max_size=self.max_size)
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 591, in read_data_frame
    frame = yield from self.read_frame(max_size)
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 632, in read_frame
    extensions=self.extensions,
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/framing.py", line 100, in read
    data = yield from reader(2)
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/asyncio/streams.py", line 663, in readexactly
    raise self._exception
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/asyncio/selector_events.py", line 723, in _read_ready
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
Error in data transfer
Traceback (most recent call last):
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 496, in transfer_data
    msg = yield from self.read_message()
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 526, in read_message
    frame = yield from self.read_data_frame(max_size=self.max_size)
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 591, in read_data_frame
    frame = yield from self.read_frame(max_size)
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 632, in read_frame
    extensions=self.extensions,
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/framing.py", line 100, in read
    data = yield from reader(2)
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/asyncio/streams.py", line 663, in readexactly
    raise self._exception
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/asyncio/selector_events.py", line 723, in _read_ready
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
Task exception was never retrieved
future: <Task finished coro=<FeedHandler._connect() done, defined at /home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py:41> exception=ConnectionClosed('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)>
Traceback (most recent call last):
  File "/home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py", line 44, in _connect
    await self._handler(websocket, feed.message_handler)
  File "/home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py", line 47, in _handler
    async for message in websocket:
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/py36/protocol.py", line 15, in __aiter__
    yield await self.recv()
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 323, in recv
    raise ConnectionClosed(self.close_code, self.close_reason)
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
Task exception was never retrieved
future: <Task finished coro=<FeedHandler._connect() done, defined at /home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py:41> exception=ConnectionClosed('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)>
Traceback (most recent call last):
  File "/home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py", line 44, in _connect
    await self._handler(websocket, feed.message_handler)
  File "/home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py", line 47, in _handler
    async for message in websocket:
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/py36/protocol.py", line 15, in __aiter__
    yield await self.recv()
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 323, in recv
    raise ConnectionClosed(self.close_code, self.close_reason)
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
Task exception was never retrieved
future: <Task finished coro=<FeedHandler._connect() done, defined at /home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py:41> exception=ConnectionClosed('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)>
Traceback (most recent call last):
  File "/home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py", line 44, in _connect
    await self._handler(websocket, feed.message_handler)
  File "/home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py", line 47, in _handler
    async for message in websocket:
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/py36/protocol.py", line 15, in __aiter__
    yield await self.recv()
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 323, in recv
    raise ConnectionClosed(self.close_code, self.close_reason)
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
Task exception was never retrieved
future: <Task finished coro=<FeedHandler._connect() done, defined at /home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py:41> exception=ConnectionClosed('WebSocket connection is closed: code = 1001 (going away), reason = CloudFlare WebSocket proxy restarting',)>
Traceback (most recent call last):
  File "/home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py", line 44, in _connect
    await self._handler(websocket, feed.message_handler)
  File "/home/bryant/workspace/cryptofeed/cryptofeed/feedhandler.py", line 47, in _handler
    async for message in websocket:
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/py36/protocol.py", line 15, in __aiter__
    yield await self.recv()
  File "/home/bryant/anaconda3/envs/cryptofeed/lib/python3.6/site-packages/websockets-4.0.1-py3.6-linux-x86_64.egg/websockets/protocol.py", line 323, in recv
    raise ConnectionClosed(self.close_code, self.close_reason)
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1001 (going away), reason = CloudFlare WebSocket proxy restarting
@bmoscon bmoscon self-assigned this Mar 10, 2018
@eliquinox
Copy link

Hi Bryant,

Have you managed to fix the ConncetionClosed exception at all?
I have ran into this issue myself many times with a number of exchanges and as such do not know a working solution.

@bmoscon
Copy link
Owner Author

bmoscon commented May 5, 2018

yes, but it depends on a fix in the websockets library. They just fixed it this week and the maintainer said a new release would be on pypi soon. Once thats done, I have changes in a branch I can merge in to fix it.

@bmoscon
Copy link
Owner Author

bmoscon commented May 5, 2018

i merged in a partial solution - when the exceptions are received, it will attempt to reconnect. The other issue the rest of my changes address (unmerged) are when the connection goes dead but there is no disconnect. They will kill the connection and reconnect.

@bmoscon bmoscon closed this as completed May 5, 2018
@rjbks rjbks mentioned this issue May 9, 2018
jik0730 added a commit to jik0730/cryptofeed that referenced this issue Oct 25, 2023
…trade-spec-change

Hotfix/gateio trade spec change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants