Skip to content

Commit

Permalink
fix: closing keepAliveWebsocker fix #1531
Browse files Browse the repository at this point in the history
  • Loading branch information
pcriadoperez committed Dec 29, 2024
1 parent d8e2ce1 commit eecda4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion binance/ws/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _get_account_socket(
url=self._get_stream_url(stream_url),
keepalive_type=path,
prefix=prefix,
exit_coro=self._exit_socket,
exit_coro=lambda p: self._exit_socket(conn_id),
is_binary=is_binary,
user_timeout=self._user_timeout,
https_proxy=self._client.https_proxy,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ async def test_socket_stopped_on_aexit(clientAsync):
ts1 = bm.trade_socket("BNBBTC")
async with ts1:
pass
assert bm._conns == {}, "socket should be removed from _conn on exit"
ts2 = bm.trade_socket("BNBBTC")
assert ts2 is not ts1, "socket should be removed from _conn on exit"
await clientAsync.close_connection()

@pytest.mark.skipif(sys.version_info < (3, 8), reason="websockets_proxy Python 3.8+")
@pytest.mark.asyncio
async def test_socket_stopped_on_aexit_futures(futuresClientAsync):
bm = BinanceSocketManager(futuresClientAsync)
ts1 = bm.futures_user_socket()
async with ts1:
pass
assert bm._conns == {}, "socket should be removed from _conn on exit"
await futuresClientAsync.close_connection()


@pytest.mark.skipif(sys.version_info < (3, 8), reason="websockets_proxy Python 3.8+")
@pytest.mark.asyncio
Expand Down

0 comments on commit eecda4c

Please sign in to comment.