binance-connector-python icon indicating copy to clipboard operation
binance-connector-python copied to clipboard

Web socket stream hangs when disconnected from the network midway

Open Riyum opened this issue 1 year ago • 1 comments

Issue subject

The Program hangs when disconnected from the network midway.

Expected behaviour

The on_error handler should throw a connection error exception.

Actual behaviour

The Program hangs after disconnecting, on reconnect there is a delay (which seems like the actual time where the machine was without a connection) which produces an output of (old ?) data.

note: if the connection isn't back, the program is stuck util killed with ctrl+c

Steps to reproduce

Go offline when it starts printing data to the screen

#!/usr/bin/env python

import time
import logging
from binance.lib.utils import config_logging
from binance.websocket.spot.websocket_stream import SpotWebsocketStreamClient

config_logging(logging, logging.DEBUG)


def message_handler(_, message):
    logging.info(message)


my_client = SpotWebsocketStreamClient(on_message=message_handler)


my_client.mini_ticker()

time.sleep(10)

logging.debug("closing ws connection")
my_client.stop()

Environment

  • Version of binance-connector-python: 3.0.0rc1
  • Python version: 3.7.12
  • Operating system Linux

Riyum avatar Apr 11 '23 22:04 Riyum

@2pd - I can see that this pull-request #228 was merged into the branch rc-3.5.0, but was then followed by c788d3a, which seemed to remove this on_websocket_error, so the issue still seems to stand.

How would you recommend we go about reconnecting and resubscribing ourselves in the event of a WebSocketTimeoutException?

MattGreeny avatar Nov 06 '23 15:11 MattGreeny