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 Life #27

Open
ThePrivatePanda opened this issue Jan 16, 2023 · 9 comments
Open

Websocket Life #27

ThePrivatePanda opened this issue Jan 16, 2023 · 9 comments

Comments

@ThePrivatePanda
Copy link
Collaborator

Websocket disconnects after a duration, could be 5 minutes, could be 4 hours- NOT caused by machine/host network.

no useful tracebacks, more information on this issue is required.

@skifli
Copy link

skifli commented Jan 16, 2023

Probably discord requesting reconnect (opcode 7)? Documented as happening randomly, whenever discord feels like it. For reconnecting, the session ID and last received sequence ID need to be sent when reconnecting

@ThePrivatePanda
Copy link
Collaborator Author

No, that has been handled.

@ThePrivatePanda
Copy link
Collaborator Author

Just occurred again and here's the traceback.

Exception in thread Thread-1 (heartbeat):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "DankCord/src/DankCord/gateway.py", line 43, in heartbeat
    self.ws.send(orjson.dumps({"op": 1, "d": None}))
  File "DankCord/.env/lib/python3.11/site-packages/websocket/_core.py", line 283, in send
    return self.send_frame(frame)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "DankCord/.env/lib/python3.11/site-packages/websocket/_core.py", line 311, in send_frame
    l = self._send(data)
        ^^^^^^^^^^^^^^^^
  File "DankCord/.env/lib/python3.11/site-packages/websocket/_core.py", line 525, in _send
    return send(self.sock, data)
           ^^^^^^^^^^^^^^^^^^^^^
  File "DankCord/.env/lib/python3.11/site-packages/websocket/_socket.py", line 143, in send
    raise WebSocketConnectionClosedException("socket is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.

@skifli
Copy link

skifli commented Jan 16, 2023

Ok, so its a bit like the reconnect. Here's a pic from the docs.
image

@skifli
Copy link

skifli commented Jan 16, 2023

You just gotta handle it like a new session.

@ThePrivatePanda
Copy link
Collaborator Author

That is handled as well. Currently, dankcord yeets the old connection and opens a new one.

@skifli
Copy link

skifli commented Jan 16, 2023

Well apparently it doesn't? Why is the error saying the connection is closed then?

@ThePrivatePanda
Copy link
Collaborator Author

It should raise the exception before, in the receive part (_events_listener). The fact that it waits for heartbeat is more troublesome

@skifli
Copy link

skifli commented Jan 16, 2023

Hmm, then idk. I don't have that much knowledge of the code.

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