You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The websockets will be returned to the main pool upon exiting the with statement in which this should be called
"""
# Ensures the batch size returned does not exceed the limit
ifnotself.connected:
# Ensures that get_socket can be called without needing to explicitly call start() beforehand
awaitself.start()
socket=awaitself._sockets.get()
try:
self._sockets_used+=1
yieldsocket
finally:
self._sockets.task_done()
self._sockets.put_nowait(socket)
self._sockets_used-=1
Here in WebsocketPool.get_socket context manager you are calling WebsocketPool.start if self.connected is True, which can easily lead to concurrent execution of WebsocketPool.start, which will lead to websocket connection leak around sockets = await gather(connect(...)).
Here is a couple of ideas of how you can improve ur websocket pool:
Require pool initialization before acquire. Yes, you have a feature that ws can be acquired without initialization (calling start()), but I think nowadays it's more like bad practice. It will be much safer and more transparent to have a context manager like initialize() that will treat pool creation / destruction;
Use asyncio locks around pool initialization / destruction (ez way, but sucks);
pythereum/pythereum/socket_pool.py
Lines 32 to 71 in 6d1d847
Here in
WebsocketPool.get_socket
context manager you are callingWebsocketPool.start
ifself.connected is True
, which can easily lead to concurrent execution ofWebsocketPool.start
, which will lead to websocket connection leak aroundsockets = await gather(connect(...))
.Here is a couple of ideas of how you can improve ur websocket pool:
initialize()
that will treat pool creation / destruction;await
around pool initialization / destruction, so no context switch can happen 😃 You can take some inspiration from https://github.com/fellowapp/asyncio-connection-pool/blob/main/asyncio_connection_pool/__init__.pyThe text was updated successfully, but these errors were encountered: