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

1001 Going Away does not trigger on_close function #63

Open
jchappe opened this issue Aug 7, 2024 · 2 comments
Open

1001 Going Away does not trigger on_close function #63

jchappe opened this issue Aug 7, 2024 · 2 comments

Comments

@jchappe
Copy link

jchappe commented Aug 7, 2024

Receiving a Close 1001 message from websocket is not triggering the on_close function and the associated retry logic.

Here is my connection snippet:

`

def start_websocket(self):
    while True:
        client = WSClient(api_key=self.api_key, api_secret=self.signing_key, on_message=self.on_message, on_open=self.on_open, on_close=self.on_close, verbose=True, timeout=5)
        try:
            client.open()
            client.subscribe(product_ids=[], channels=["user"])
            client.run_forever_with_exception_check()
        except WSClientConnectionClosedException as e:
            logging.info(f"User Orders Websocket Connection closed! Retry attempts exhausted. {e}")
        except WSClientException as e:
            logging.info(f"User Orders Websocket Error encountered!. {e}")
        time.sleep(.2)`

And here is the logging:

2024-08-06 22:53:08 - websockets.client - DEBUG - % sending keepalive ping
2024-08-06 22:53:08 - websockets.client - DEBUG - > PING 8d 71 87 e4 [binary, 4 bytes]
2024-08-06 22:53:08 - websockets.client - DEBUG - < CLOSE 1001 (going away) [2 bytes]
2024-08-06 22:53:08 - websockets.client - DEBUG - = connection is CLOSING
2024-08-06 22:53:08 - websockets.client - DEBUG - > CLOSE 1001 (going away) [2 bytes]
2024-08-06 22:53:08 - websockets.client - DEBUG - = connection is CLOSED

Copy link

github-actions bot commented Aug 7, 2024

Thank you for reporting! If this is an SDK specific issue, we will look into it and get back to you soon. If this is an API related request, report it in our Advanced API Discord instead (use this invite link if it's your first time accessing the Discord).

@urischwartz-cb
Copy link
Contributor

I believe this is because a 1001 error is not considered an unexpected connection closure and therefore the retry logic would not be triggered. See here on how ConnectionClosedOK errors are handled vs how ConnectionClosedError errors are handled.

Furthermore, your on_close function is only called when you manually close the connection, not on an error.

How often are you seeing this behavior? I will raise this internally with the the team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants