Skip to content
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

Merged
merged 2 commits into from May 23, 2017

Conversation

jimmylai
Copy link

@jimmylai jimmylai commented May 21, 2017

@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.

jimmylai added 2 commits May 20, 2017 18:40
…ure-close-loop

[Asyncio] Call remove_done_callback in finally section to prevent orphan future cause RuntimeError: Event loop stopped before Future completed.
@the-knights-who-say-ni
Copy link

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!

@AraHaan
Copy link
Contributor

AraHaan commented May 21, 2017

Mind making an bpo issue for this as well? Also did you sign the CLA?

@jimmylai jimmylai changed the title [asyncio] bug: orphan future close loop and cause "RuntimeError: Event loop stopped before Future completed." [asyncio] bpo-26171 bug: orphan future close loop and cause "RuntimeError: Event loop stopped before Future completed." May 21, 2017
@jimmylai jimmylai changed the title [asyncio] bpo-26171 bug: orphan future close loop and cause "RuntimeError: Event loop stopped before Future completed." [asyncio] bpo-30423 bug: orphan future close loop and cause "RuntimeError: Event loop stopped before Future completed." May 21, 2017
@jimmylai
Copy link
Author

@AraHaan I just created an issue 30423. CLA was signed yesterday, still waiting for status update.

@ambv
Copy link
Contributor

ambv commented May 23, 2017

Contribution also covered by Facebook CCLA.

@ambv ambv merged commit 21b3e04 into python:master May 23, 2017
@1st1
Copy link
Member

1st1 commented May 23, 2017

Is it possible to add a unittest for this (especially important for other loops like uvloop etc)?

@1st1
Copy link
Member

1st1 commented May 23, 2017

This also needs backports to 3.6 and 3.5.

@ambv
Copy link
Contributor

ambv commented May 23, 2017

@jimmylai Thanks for the PR, Yury is right, let's add a test for this.

@1st1, I'll backport it to 3.6 now with cherry-picker. 3.5 might be trickier, I'll look.

ambv pushed a commit to ambv/cpython that referenced this pull request May 23, 2017
ambv pushed a commit to ambv/cpython that referenced this pull request May 23, 2017
ambv added a commit that referenced this pull request May 23, 2017
ambv added a commit that referenced this pull request May 23, 2017
@1st1
Copy link
Member

1st1 commented May 23, 2017

@jimmylai Thanks for the PR, Yury is right, let's add a test for this.
@1st1, I'll backport it to 3.6 now with cherry-picker. 3.5 might be trickier, I'll look.

Thanks! Will you guys make a separate PR for the tests?

@jimmylai
Copy link
Author

@1st1 @ambv I'll create a separate PR for unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants