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

websocket 이 연결이 끊어지네요 #19

Open
pcompassion opened this issue Apr 10, 2021 · 5 comments
Open

websocket 이 연결이 끊어지네요 #19

pcompassion opened this issue Apr 10, 2021 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@pcompassion
Copy link

asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 2 expected bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/pyupbit/websocket_api.py", line 54, in run
    self.__aloop.run_until_complete(self.__connect_socket())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/pyupbit/websocket_api.py", line 48, in __connect_socket
    recv_data = await websocket.recv()
  File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/websockets/protocol.py", line 509, in recv                                                 await self.ensure_open()                                                                                                                                      File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/websockets/protocol.py", line 803, in ensure_open                                          raise self.connection_closed_exc()                                                                                                                          websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason
@PYTHONKOR
Copy link

PYTHONKOR commented Apr 21, 2021

질문에 영양가 없는 댓글이라 삭제합니다. 😂

@Codejune
Copy link

웹소켓의 경우 업비트 서버와 클라이언트(본인) 간의 데이터 교류가 없을경우 임의적으로 중단하는 현상이 발생합니다. 업비트 api문서에 따르면 ping-pong을 지원하니 이를 반영하는 것이 좋을 것 같습니다

@mr-yoo
Copy link
Collaborator

mr-yoo commented May 5, 2021

@Codejune 님 말씀이 맞습니다.

서버에서는 기본적으로 아무런 데이터도 수/발신 되지 않은 채 약 120초가 경과하면 Idle Timeout으로 WebSocket Connection을 종료합니다. 이를 방지하기 위해 클라이언트에서 서버로 PING 메시지를 보내서 Connection을 유지하고, WebSocket 서버의 상태와 WebSocket Connection Status를 파악할 수 있습니다.
reference : https://docs.upbit.com/docs/upbit-quotation-websocket#client-to-server-ping

mr-yoo added a commit that referenced this issue May 5, 2021
 - 기존에는 None으로 설정하던 것을 60s 단위로 ping-pong 하도록 수정
 - 참고로 업비트는 120초 동안 응답이없으면 웹소켓을 종료함
@mr-yoo
Copy link
Collaborator

mr-yoo commented May 5, 2021

다음 commit에서 ping interval을 60s로 설정을 했습니다.
3968773

async with websockets.connect(uri, ping_interval=60) as websocket:
    data = [{"ticket": str(uuid.uuid4())[:6]}, {"type": self.type, "codes": self.codes}]
    await websocket.send(json.dumps(data))

문제가 재현 된다면 알려주세요.

@mr-yoo mr-yoo self-assigned this May 5, 2021
@mr-yoo mr-yoo added bug Something isn't working closing-candidates labels May 5, 2021
@littlehome-eugene
Copy link

좀 다른 에러가 나네요 이제 (ping 60s 적용코드 사용중입니다)

Process WebSocketManager-1:
Traceback (most recent call last):
  File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/websockets/protocol.py", line 838, in transfer_data
    await asyncio.shield(self._put_message_waiter)
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/pyupbit/websocket_api.py", line 54, in run
    self.__aloop.run_until_complete(self.__connect_socket())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/pyupbit/websocket_api.py", line 48, in __connect_socket
    recv_data = await websocket.recv()
  File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/websockets/protocol.py", line 509, in recv
    await self.ensure_open()
  File "/home/eugenekim/virtualenvs/snowball/lib/python3.8/site-packages/websockets/protocol.py", line 803, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants