Skip to content

[asyncio] bpo-30423 bug: orphan future close loop and cause "RuntimeError: Event loop stopped before Future completed."#1688

Merged
ambv merged 2 commits into
python:masterfrom
jimmylai:master
May 23, 2017
Merged

[asyncio] bpo-30423 bug: orphan future close loop and cause "RuntimeError: Event loop stopped before Future completed."#1688
ambv merged 2 commits into
python:masterfrom
jimmylai:master

Conversation

@jimmylai

@jimmylai jimmylai commented May 21, 2017

Copy link
Copy Markdown

@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
Copy Markdown

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

AraHaan commented May 21, 2017

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Author

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

@ambv

ambv commented May 23, 2017

Copy link
Copy Markdown
Contributor

Contribution also covered by Facebook CCLA.

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

1st1 commented May 23, 2017

Copy link
Copy Markdown
Member

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

@1st1

1st1 commented May 23, 2017

Copy link
Copy Markdown
Member

This also needs backports to 3.6 and 3.5.

@ambv

ambv commented May 23, 2017

Copy link
Copy Markdown
Contributor

@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

1st1 commented May 23, 2017

Copy link
Copy Markdown
Member

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

6 participants