From eecda4ccf02c605581c78de4ed2d98a259d975ee Mon Sep 17 00:00:00 2001 From: Pablo Date: Sun, 29 Dec 2024 23:13:51 +0000 Subject: [PATCH] fix: closing keepAliveWebsocker fix #1531 --- binance/ws/streams.py | 2 +- tests/test_streams.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/binance/ws/streams.py b/binance/ws/streams.py index b5fb46e3..ed425bc8 100755 --- a/binance/ws/streams.py +++ b/binance/ws/streams.py @@ -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, diff --git a/tests/test_streams.py b/tests/test_streams.py index 7e81aa6e..a2ab6634 100644 --- a/tests/test_streams.py +++ b/tests/test_streams.py @@ -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