Skip to content

bpo-40115: Fix refleak in test_asyncio #19282

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

Merged

Conversation

aeros
Copy link
Contributor

@aeros aeros commented Apr 1, 2020

My change to remove daemon threads in concurrent.futures (#19149) revealed a subtle issue in test_events.test_run_in_executor_cancel: it does not properly clean up the executor's resources. This should be done by calling loop.shutdown_default_executor() prior to loop.close(), as is done in asyncio.run().

Before:

[aeros:~/repos/aeros-cpython]$ ./python -m test --fail-env-changed -R 3:3 test_asyncio -m test.test_asyncio.test_events.EPollEventLoopTests.test_run_in_executor_cancel
0:00:00 load avg: 0.63 Run tests sequentially
0:00:00 load avg: 0.63 [1/1] test_asyncio
beginning 6 repetitions
123456
......
test_asyncio leaked [1, 1, 1] references, sum=3
test_asyncio leaked [2, 1, 1] memory blocks, sum=4
test_asyncio failed

== Tests result: FAILURE ==

1 test failed:
    test_asyncio

Total duration: 3.2 sec
Tests result: FAILURE

After:

[aeros:~/repos/aeros-cpython]$ ./python -m test --fail-env-changed -R 3:3 test_asyncio -m test.test_asyncio.test_events.EPollEventLoopTests.test_run_in_executor_cancel
0:00:00 load avg: 0.24 Run tests sequentially
0:00:00 load avg: 0.24 [1/1] test_asyncio
beginning 6 repetitions
123456
......

== Tests result: SUCCESS ==

1 test OK.

Total duration: 3.5 sec
Tests result: SUCCESS

/cc @vstinner @pitrou @1st1

https://bugs.python.org/issue40115

@aeros aeros requested review from 1st1 and asvetlov as code owners April 1, 2020 20:40
@bedevere-bot bedevere-bot added tests Tests in the Lib/test dir awaiting review labels Apr 1, 2020
@aeros aeros added topic-asyncio skip news 🔨 test-with-buildbots Test PR w/ buildbots; report in status section labels Apr 1, 2020
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @aeros for commit 13fa9a966ccf1a9c996085483a3ea1d351dee409 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 1, 2020
@aeros
Copy link
Contributor Author

aeros commented Apr 1, 2020

Prior to merging, we should wait for the refleak tests to pass.

@aeros aeros requested review from vstinner and pitrou April 1, 2020 20:47
@aeros
Copy link
Contributor Author

aeros commented Apr 1, 2020

The Ubuntu PR test in Azure Pipelines seems to be failing because the following URL is dead: https://www.openssl.org/source/openssl-1.1.1d.tar.gz. See line 184 of the build log.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@aeros
Copy link
Contributor Author

aeros commented Apr 1, 2020

Edit: I confirmed the refleak in test_threading incorrectly, so I'm currently redoing it.

I redid the tests locally directly on top of b61b818, and it was passing for test_threading, so it looks like it was introduced in a later commit:

[aeros:~/repos/aeros-cpython]$ ./python -m test --fail-env-changed -R 3:3 test_threading (bpo39812-cf-remove-daemon) 
0:00:00 load avg: 0.65 Run tests sequentially
0:00:00 load avg: 0.65 [1/1] test_threading
beginning 6 repetitions
123456
......
test_threading passed in 1 min

== Tests result: SUCCESS ==

1 test OK.

Total duration: 1 min
Tests result: SUCCESS

@aeros
Copy link
Contributor Author

aeros commented Apr 2, 2020

@vstinner From carefully looking over all of the buildbot logs and my own local testing, I believe the refleaks showing in the tests are entirely separate from both this PR and #19149. I strongly suspect they were introduced in-between b61b818 and the latest commit to master.

With that in mind, is it okay to merge this PR instead of reverting b61b818?

@vstinner
Copy link
Member

vstinner commented Apr 2, 2020

Without this change, ./python -m test --fail-env-changed -R 3:3 test_asyncio -m test.test_asyncio.test_events.EPollEventLoopTests.test_run_in_executor_cancel leaks.

With this change, it no longer leaks. So I confirm that this PR fix https://bugs.python.org/issue40115

@vstinner
Copy link
Member

vstinner commented Apr 2, 2020

The Ubuntu PR test in Azure Pipelines seems to be failing because the following URL is dead: https://www.openssl.org/source/openssl-1.1.1d.tar.gz. See line 184 of the build log.

I fixed it with commit 224e1c3: you need to rebase your PR on top of it.

@aeros aeros force-pushed the bpo40115-test_asyncio-run_in_executor_cancel branch from 13fa9a9 to 93fde8c Compare April 2, 2020 01:54
@vstinner
Copy link
Member

vstinner commented Apr 2, 2020

On "buildbot/AMD64 Fedora Stable Refleaks PR", I see:

test_threading leaked [38, 38, 38] references

That's an unrelated regression: I created https://bugs.python.org/issue40149 I used test.bisect_cmd to identify one leaking test and then I used git bisect to identify which commit introduced the regression.

With that in mind, is it okay to merge this PR instead of reverting b61b818?

Sure.

@aeros
Copy link
Contributor Author

aeros commented Apr 2, 2020

@vstinner Thanks for the clarification. It's my first time addressing a regression that I introduced, so I just wanted to double check.

Also, I was unaware of test.bisect_cmd, I'll look into that. I've more recently starting making use of git bisect though, after reading about it in a Committers topic on discuss.python.org.

(Note: the GitHub Actions Ubuntu test seems to be intermittently failing in the "Install dependencies" stage across several PRs. If someone hasn't already, I'll likely open a python-dev thread tomorrow to bring attention to it.)

@aeros aeros removed the DO-NOT-MERGE label Apr 2, 2020
@vstinner vstinner merged commit 8ec7cb5 into python:master Apr 2, 2020
@aeros aeros deleted the bpo40115-test_asyncio-run_in_executor_cancel branch April 3, 2020 07:47
@aeros
Copy link
Contributor Author

aeros commented May 21, 2020

Oh crap, did that just revert the commit in a single click @vstinner? I saw something in the UI with the post-commit checks and wanted to check up on it; I accidentally misclicked "revert commit" instead of "view details".

Edit: Never mind, fortunately it looks like that just created a separate branch in the cpython repository titled revert-19282-bpo40115-test_asyncio-run_in_executor_cancel. I'll reach out on python-committers for the appropriate way to clean up that branch. Sorry about the confusion.

Edit2: Ned helped to clean up the branch after my email to python-committers, so there is no issue now. I'll try to be more careful w/ that in the future and keep in mind the active branches page for future reference.

@aeros aeros restored the bpo40115-test_asyncio-run_in_executor_cancel branch May 21, 2020 07:29
@vstinner
Copy link
Member

Oh crap, did that just revert the commit in a single click @vstinner?

You cannot push a commit directly. Changes must go through a PR. I don't think that a single click is enough to revert a change :-)

@aeros
Copy link
Contributor Author

aeros commented May 27, 2020

You cannot push a commit directly. Changes must go through a PR. I don't think that a single click is enough to revert a change :-)

Yeah, I figured that out after I realized that it just created a branch; it's good to know for sure though. Thanks for clarifying, I'm still very new to having commit privileges. :-)

(It gave me quite a bit of anxiety in the moment, but after Ned's response I realized that it was a much bigger deal in my mind than it actually was.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir topic-asyncio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants