-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[asyncio] bpo-30423 bug: orphan future close loop and cause "RuntimeError: Event loop stopped before Future completed." #1688
Conversation
…ure-close-loop [Asyncio] Call remove_done_callback in finally section to prevent orphan future cause RuntimeError: Event loop stopped before Future completed.
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
Mind making an bpo issue for this as well? Also did you sign the CLA? |
@AraHaan I just created an issue 30423. CLA was signed yesterday, still waiting for status update. |
Contribution also covered by Facebook CCLA. |
Is it possible to add a unittest for this (especially important for other loops like uvloop etc)? |
This also needs backports to 3.6 and 3.5. |
(cherry picked from commit 21b3e04)
(cherry picked from commit 21b3e04)
@1st1 this is the fix we did to fix the orphan future problem we saw in Instagram web service.
Problem:
"RuntimeError: Event loop stopped before Future completed." throws when calling run_until_complete().
We investigate and find out some orphan futures stay in the event loop before we run another run_until_complete(another_async_func()).
The orphan future has pending state and is attached with _run_until_complete_cb from previous run_until_complete.
It happens because the orphan future thrown Exception and then raise, thus remove_done_callback(_run_until_complete_cb) didn't called.
Move it to finally section can fix it.
With this patch, we stop seeing the Runtime Error.
Thanks @ambv for brainstorming the problem together.