Skip to content

Commit fb037fb

Browse files
committed
aiorpcx: adapt TaskGroup._add_task monkey-patch to upstream fix
- upstream fix is at kyuupichan/aiorpcX@a0be71c , but it's not yet released - prev monkey-patch was causing issues if used with aiorpcx that already has the upstream fix: ``` INFO:SessionManager:TCP server listening on 127.0.0.1:51001 INFO:SessionManager:SSL server listening on 127.0.0.1:51002 INFO:PeerManager:peer discovery: ON INFO:PeerManager:announce ourself: True INFO:PeerManager:my clearnet self: None INFO:PeerManager:force use of proxy: False INFO:PeerManager:beginning peer discovery... INFO:PeerManager:trying to detect proxy on "localhost" ports [9050, 9150, 1080] Exception in callback TaskGroup._on_done(<Task finishe...> result=None>) handle: <Handle TaskGroup._on_done(<Task finishe...> result=None>)> Traceback (most recent call last): File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run self._context.run(self._callback, *self._args) File "/home/user/wspace/aiorpcX/aiorpcx/curio.py", line 147, in _on_done self.tasks.remove(task) KeyError: <Task finished name='Task-29' coro=<PeerManager._refresh_blacklist() done, defined at /home/user/wspace/electrumx/electrumx/server/peers.py:144> result=None> Exception in callback TaskGroup._on_done(<Task finishe...> result=None>) handle: <Handle TaskGroup._on_done(<Task finishe...> result=None>)> Traceback (most recent call last): File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run self._context.run(self._callback, *self._args) File "/home/user/wspace/aiorpcX/aiorpcx/curio.py", line 147, in _on_done self.tasks.remove(task) KeyError: <Task finished name='Task-31' coro=<PeerManager._import_peers() done, defined at /home/user/wspace/electrumx/electrumx/server/peers.py:135> result=None> INFO:PeerManager:detected SOCKS5 proxy at localhost:9050, auth: none Exception in callback TaskGroup._on_done(<Task finishe...> result=None>) handle: <Handle TaskGroup._on_done(<Task finishe...> result=None>)> Traceback (most recent call last): File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run self._context.run(self._callback, *self._args) File "/home/user/wspace/aiorpcX/aiorpcx/curio.py", line 147, in _on_done self.tasks.remove(task) KeyError: <Task finished name='Task-30' coro=<PeerManager._detect_proxy() done, defined at /home/user/wspace/electrumx/electrumx/server/peers.py:182> result=None> ```
1 parent 84b49f5 commit fb037fb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

electrumx/lib/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,12 @@ async def join(self):
385385
# This is to plug a memory-leak, see https://github.com/kyuupichan/aiorpcX/issues/46 .
386386
# Note: this breaks the TaskGroup.results and TaskGroup.exceptions APIs
387387
# but we are not using them anyway.
388+
# TODO: this monkey-patch can be removed once we require aiorpcx versions that
389+
# have the upstream fix for #46.
388390
def _patched_TaskGroup_add_task(self: 'aiorpcx.TaskGroup', task):
389391
self._orig_add_task(self, task)
390-
self.tasks.clear()
392+
if not hasattr(self, "_retain"):
393+
self.tasks.clear()
391394

392395
aiorpcx.TaskGroup._orig_add_task = staticmethod(aiorpcx.TaskGroup._add_task)
393396
aiorpcx.TaskGroup._add_task = _patched_TaskGroup_add_task

0 commit comments

Comments
 (0)