GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-102251: add missing cleanups for `test_import` by sunmy2019 · Pull Request #104796 · python/cpython

Conversation

@sunmy2019

@sunmy2019 sunmy2019 commented May 23, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Leak reasons are described here.

#103879 (comment)

For 1, the fix is straightforward.

For 2, I added 2 clean-up functions and trigger them manually.

For 3, I haven't figured out a clean solution, but I would prefer to skip it under ref leak modes only. So I introduce a new method because AFAIK there isn't a way to skip only ref leak tests.

  • Issue: Fix Refleak in test_import #102251

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sunmy2019
add some cleanups
db000e8
@bedevere-bot bedevere-bot mentioned this pull request May 23, 2023
Fix Refleak in test_import #102251
Closed
@sunmy2019
sunmy2019 marked this pull request as ready for review May 23, 2023 10:27
@sunmy2019
sunmy2019 requested review from brettcannon, encukou, ericsnowcurrently, ncoghlan and warsaw as code owners May 23, 2023 10:27
@bedevere-bot bedevere-bot added the awaiting review label May 23, 2023
@sunmy2019 sunmy2019 added the skip news label May 23, 2023
@Eclips4

Eclips4 commented May 23, 2023

Copy link
Copy Markdown
Member

As I understand, this doesn't solve problem, just "shuts up" the noise from known refleaks on test_import, right?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019

sunmy2019 commented May 23, 2023

Copy link
Copy Markdown
Member Author

As I understand, this doesn't solve problem, just "shuts up" the noise from known refleaks on test_import, right?

That is not true. I do think I did resolve all ref leaks on Linux.

But I did not test it on Windows.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Eclips4

Eclips4 commented May 23, 2023

Copy link
Copy Markdown
Member

As I understand, this doesn't solve problem, just "shuts up" the noise from known refleaks on test_import, right?

That is not true. I do think I did resolve all ref leaks on Linux.

But I did not test it on Windows.

Oh, seems on Windows problem doesn't solved. I rebuilt intepreter with your changes and got it:

 ./python -m test -R 3:3 test_import
Running Debug|x64 interpreter...
0:00:00 Run tests sequentially
0:00:00 [1/1] test_import
beginning 6 repetitions
123456
......
test_import leaked [41, 43, 40] references, sum=124
test_import leaked [41, 41, 40] memory blocks, sum=122
test_import failed (reference leak)

== Tests result: FAILURE ==

1 test failed:
    test_import

Total duration: 28.7 sec
Tests result: FAILURE
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019
remove the sys.argv trick
e6bc99c
sunmy2019
sunmy2019 commented May 23, 2023
View reviewed changes
Comment thread Lib/test/test_import/__init__.py
Comment on lines -1983 to -1994
if '-R' in sys.argv or '--huntrleaks' in sys.argv:
# https://github.com/python/cpython/issues/102251
raise unittest.SkipTest('unresolved refleaks (see gh-102251)')

@sunmy2019 sunmy2019 May 23, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This trick cannot be used with ./python -m test -j n, thus causing failures on CI.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sunmy2019

sunmy2019 commented May 23, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

All ref leaks on Linux come from SinglephaseInitTests, but running

 .\python_d.exe -m test test_import -R 3:3 -v -i *SinglephaseInitTests*

on Windows does give ref leaks

OK (skipped=5)
.
test_import leaked [41, 43, 40] references, sum=124
test_import leaked [41, 41, 40] memory blocks, sum=122
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019

sunmy2019 commented May 23, 2023

Copy link
Copy Markdown
Member Author

@Eclips4 Can you bisect which test leaks ref?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Eclips4

Eclips4 commented May 23, 2023

Copy link
Copy Markdown
Member

@Eclips4 Can you bisect which test leaks ref?

Sure!
If we delete ImportTests/test_concurrency refleak tests are passed. Seems that problem in this test

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Eclips4

Eclips4 commented May 23, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Also, I tried to found commit which introduce this reference leak ( in test_concurrency)
and again bisected to #94504..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019
Merge branch 'main' into pythongh-102251
ea8e894
@Eclips4

Eclips4 commented May 26, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Oh, seems your solution also works on Windows. ( I forgot to add -j 1 parameter 🤦‍♂️ , sorry)
But problem with test_concurrency still there, and that's interesting, because it doesn't reproducible on Linux.

Probably, it should be a another PR (at the current moment I still haven't found a solution).
My some notes about it:
If we delete these lines from test_concurrency:

sys.modules.pop('package', None)
sys.modules.pop('package.submodule', None)

Refleak tests will pass.
Also, this problem confirms that Windows runner in buildbots fleet really needed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brettcannon
brettcannon removed their request for review May 29, 2023 17:06
erlend-aasland
erlend-aasland reviewed May 29, 2023
View reviewed changes

@erlend-aasland erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The libregrtest modification seems way too hacky for my taste. What happens if you apply my suggestion for _testsinglephase.c, and revert all other changes introduced in this PR?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zware reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Modules/_testsinglephase.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland
erlend-aasland reviewed May 29, 2023
View reviewed changes
Comment thread Modules/_testsinglephase.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019

sunmy2019 commented May 30, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

revert all other changes introduced in this PR?

There are 3 leak points when running in Linux. Applying your suggestions only fixes one of them.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sunmy2019 added 2 commits May 30, 2023 11:36
@sunmy2019
Merge branch 'main' of github.com:python/cpython into pythongh-102251
5dbb8c3
@sunmy2019
follow @erlend-aasland's advice
c6b42ee
@erlend-aasland

erlend-aasland commented May 30, 2023

Copy link
Copy Markdown
Contributor

revert all other changes introduced in this PR?

There are 3 leak points when running in Linux. Applying your suggestions only fixes one of them.

I suggest you turn this PR1 into a fix for this one issue, so we can land that fix. The fix is obvious; I can land that for you today. The rest of the changes are controversial; I think it would be wise to separate them out.

Also: please don't tag people with in commit messages. Those commits ends up as noise in the GitHub notifications page.

Footnotes

  1. or create a new PR for this ↩

zware reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019

sunmy2019 commented May 30, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author
  1. or create a new PR for this ↩

I will create a new one.


#105082

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019
revert this as this would be intended at pythongh-104796
2ee60e2
@erlend-aasland

erlend-aasland commented May 30, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Status for buildbot run for commit 20307d0:

  • buildbot/AMD64 Fedora Stable Refleaks PR: test_peg_generator leaked
  • buildbot/AMD64 RHEL7 Refleaks PR: test_peg_generator leaked
  • buildbot/AMD64 RHEL8 Refleaks PR: test_peg_generator leaked
  • buildbot/PPC64LE RHEL8 Refleaks PR: test_peg_generator leaked
  • buildbot/aarch64 RHEL8 Refleaks PR: test_peg_generator leaked
  • buildbot/s390x Fedora Refleaks PR: test_peg_generator leaked
  • buildbot/s390x RHEL7 Refleaks PR: test_peg_generator leaked
  • buildbot/s390x RHEL8 Refleaks PR: test_peg_generator leaked
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019

This comment was marked as outdated.

Sign in to view
ericsnowcurrently
ericsnowcurrently approved these changes May 31, 2023
View reviewed changes

@ericsnowcurrently ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels May 31, 2023
@ericsnowcurrently

ericsnowcurrently commented May 31, 2023

Copy link
Copy Markdown
Member

GitHub took me straight to "Files changed", so I didn't see the other comments before I gave an approving review. The change looks fine to me, but please be sure to address any other comments before this is merged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019

sunmy2019 commented May 31, 2023

Copy link
Copy Markdown
Member Author

The second part is split to #105085

I will make this PR focus on the 3rd
part of the problem.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland erlend-aasland mentioned this pull request May 31, 2023
gh-102251: Explicitly free state for test modules with state in test_import #105085
Merged
sunmy2019 added 2 commits June 1, 2023 10:26
@sunmy2019
Merge branch 'main' of github.com:python/cpython into pythongh-102251
75230b0
@sunmy2019
rebase after changes to python#105085
695fd16
@sunmy2019

sunmy2019 commented Jun 1, 2023

Copy link
Copy Markdown
Member Author

Now this PR only has changes related to the 3rd part.


test_basic_multiple_interpreters_deleted_no_reset deliberately leaks things. And we have a "no-leak" version test right after this: test_basic_multiple_interpreters_reset_each.

I think the correct thing to do here is to skip this specific test when hunting ref leaks.


However, the previous approach does not work under -j. And the test main has no way to pass the information to the actual test. So I came up with the name trick.

I am open to any other methods.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland erlend-aasland mentioned this pull request Jun 2, 2023
gh-104614: Make Sure ob_type is Always Set Correctly by PyType_Ready() #105122
Merged
erlend-aasland
erlend-aasland reviewed Jun 5, 2023
View reviewed changes
Comment thread Lib/test/libregrtest/main.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jun 20, 2023
gh-105310: add decorator to skip rerunning tests #105311
Closed
test_basic_multiple_interpreters_deleted_no_reset() of test_imp/test_import leaks references #106000
Closed
sunmy2019 added 2 commits June 23, 2023 11:33
@sunmy2019
Merge branch 'main' of github.com:python/cpython into pythongh-102251
0480053
@sunmy2019
collect tests in a single class
5934e50
@sunmy2019
sunmy2019 removed the request for review from encukou June 23, 2023 04:27
@sunmy2019 sunmy2019 added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Jun 23, 2023
@bedevere-bot

bedevere-bot commented Jun 23, 2023

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @sunmy2019 for commit 5934e50 🤖

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Jun 23, 2023
sunmy2019
sunmy2019 commented Jun 23, 2023
View reviewed changes
Comment thread Lib/test/test_import/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sunmy2019
Update Lib/test/test_import/__init__.py
60b4921
@sunmy2019 sunmy2019 added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Jun 23, 2023
@bedevere-bot

bedevere-bot commented Jun 23, 2023

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @sunmy2019 for commit 60b4921 🤖

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Jun 23, 2023
@erlend-aasland erlend-aasland mentioned this pull request Jun 23, 2023
gh-102251: Disable non-rerunnable test in test_import #106013
Merged
@erlend-aasland

erlend-aasland commented Jun 23, 2023

Copy link
Copy Markdown
Contributor

Closing in favour of gh-106013. Thanks for the effort you've put into this @sunmy2019; highly appreciated!

Also, thanks for keeping up with me; sorry for pushing you in different directions, but my opinions changed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland erlend-aasland closed this Jun 23, 2023
@sunmy2019 sunmy2019 mentioned this pull request Jun 28, 2023
test_import.test_concurrency leaks ref on Windows #106176
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@erlend-aasland erlend-aasland erlend-aasland left review comments
@ericsnowcurrently ericsnowcurrently ericsnowcurrently approved these changes
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting merge skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@sunmy2019 @Eclips4 @erlend-aasland @bedevere-bot @ericsnowcurrently
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.