Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ibind/base/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ def _run_websocket(self, wsa: WebSocketApp):

try:
# the timeout is set to a little sooner than the interval
wsa.run_forever(ping_interval=self._ping_interval, ping_timeout=self._ping_interval * 0.95, sslopt=self._sslopt)
# skip_utf8_validation=True: IBKR occasionally emits non-UTF-8 bytes (e.g. 0x99) in text frames,
# which crashes the run_forever thread before on_close fires. Decoding is handled above this layer.
wsa.run_forever(
ping_interval=self._ping_interval,
ping_timeout=self._ping_interval * 0.95,
sslopt=self._sslopt,
skip_utf8_validation=True,
)

except ValueError as e:
if 'url is invalid' in str(e):
Expand Down
2 changes: 2 additions & 0 deletions test/integration/base/test_websocket_client_i.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def _verify_started(ws_client: WsClient, wsa_mock: MagicMock):
sslopt=ws_client._sslopt,
ping_interval=ws_client._ping_interval,
ping_timeout=0.95 * ws_client._ping_interval,
skip_utf8_validation=True,
)
wsa_mock._on_open.assert_called_with(wsa_mock)

Expand Down Expand Up @@ -260,6 +261,7 @@ def run_forever_exception(
sslopt: dict = None,
ping_interval: float = 0,
ping_timeout: Optional[float] = None,
skip_utf8_validation: bool = False,
):
wsa_mock.run_forever.side_effect = old_run_forever
raise RuntimeError(_ERROR_MESSAGE)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/base/websocketapp_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def close(wsa_mock: MagicMock, status: str = None):
wsa_mock._on_close(wsa_mock, None, None)


def run_forever(wsa_mock: MagicMock, sslopt: dict = None, ping_interval: float = 0, ping_timeout: Optional[float] = None):
def run_forever(wsa_mock: MagicMock, sslopt: dict = None, ping_interval: float = 0, ping_timeout: Optional[float] = None, skip_utf8_validation: bool = False):
wsa_mock.keep_running = True
wsa_mock._on_open(wsa_mock)

Expand Down
Loading