Closed jsdanielh closed 2 years ago
Per my comments here: #15 (comment)
It would be great to have a few more adjustments
I have applied your suggestion and also went and use asyncio.wait
as you suggested in #15 (comment) which I also think it's a better solution.
Let me know if you have more comments.
Looks great! @jsdanielh
Being a sensitive spot I would love another eye on this from one of you - @roekatz , @asafc
@jsdanielh @orweis The fix in
wait_for_response
looks correct to me (canceling theself._closed.wait()
task which was left uncanceled in the previous implementation).But I don't really understand why it's not enough and we also need to discourage the use of None timeout. Do you mean that it leaks if the RPC doesn't return? (because to me that doesn't really count as a leak)
Yeah, you're right. It leaked when using as_completed
but I don't think it still leaks now with the change to wait
and returning when the first completes. Also I agree that if RPC doesn't return it isn't a leak. I'll amend the commit to remove the warnings I added on using None
as a timeout
Fix memory leak in the method
wait_for_response
ofRpcChannel
. As documented in #15, when callingasyncio.as_completed
it actually creates a task to wait for theself._close
event. In a long livedRpcChannel
that event never happens and thus that future continues to run until theclose
method is called. Since the task is created with eachRpcChannel
'scall
method, this could end up leaking objects such as_asyncio.Task
,_asyncio.Future
andcoroutine
.This change changes a the
wait_for_response
method to useasyncio.wait
with atimeout
andFIRST_COMPLETED
for thereturned_when
argument such that we can obtain all pending futures after the first completed and cancel them to avoid the leak. This warrants that thewait
for theself._close
event future will be cancelled and then no future/task/coroutine is leaked.Also add some styling changes and fix some typos.
This fixes #15.