Skip to content

gh-87298: Add tests for find_in_strong_cache() bug in _zoneinfo #24829

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

Conversation

ZackerySpytz
Copy link
Contributor

@ZackerySpytz ZackerySpytz commented Mar 11, 2021

@ZackerySpytz ZackerySpytz force-pushed the bpo-43132-find_in_strong_cache-_zoneinfo-tests branch from 7c640db to 1f7a1fa Compare March 12, 2021 01:48
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 12, 2021
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Aug 5, 2022
@iritkatriel iritkatriel requested a review from pganssle May 14, 2023 13:49
@erlend-aasland erlend-aasland changed the title bpo-43132: Add tests for find_in_strong_cache() bug in _zoneinfo gh-87298: Add tests for find_in_strong_cache() bug in _zoneinfo Jan 5, 2024
@erlend-aasland erlend-aasland self-requested a review January 5, 2024 13:01
@python-cla-bot
Copy link

python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@StanFromIreland
Copy link
Member

StanFromIreland commented Jun 29, 2025

Serhiy, since you merged #24450, maybe you can review the tests?

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) July 1, 2025 14:37
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jul 1, 2025
@serhiy-storchaka serhiy-storchaka merged commit 12ce16b into python:main Jul 1, 2025
43 checks passed
@miss-islington-app
Copy link

Thanks @ZackerySpytz for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 1, 2025
…pythonGH-24829)

(cherry picked from commit 12ce16b)

Co-authored-by: Zackery Spytz <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2025

GH-136181 is a backport of this pull request to the 3.14 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 1, 2025
…pythonGH-24829)

(cherry picked from commit 12ce16b)

Co-authored-by: Zackery Spytz <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jul 1, 2025
@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2025

GH-136182 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jul 1, 2025
@@ -1507,6 +1530,26 @@ def test_clear_cache_two_keys(self):
self.assertIsNot(dub0, dub1)
self.assertIs(tok0, tok1)

def test_clear_cache_refleak(self):
Copy link
Member

Choose a reason for hiding this comment

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

Apparently I wrote this function 4 years ago, but coming back to it now it is opaque as heck, so we should probably describe what this test is about.

Suggested change
def test_clear_cache_refleak(self):
def test_clear_cache_refleak(self):
# bpo-43132: The portion of the C implementation of ZoneInfo that
# ejects specific keys from the strong cache (i.e. the LRU cache) was
# leaking references if comparing to the key object failed; because the
# strong cache is not currently implemented for subclasses, this test
# only really applies to the C implementation of the ZoneInfo class.

self.klass(key)
key.allow_comparisons = False
try:
# Note: This is try/except rather than assertRaises because
Copy link
Member

Choose a reason for hiding this comment

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

I realize that I wrote this function, but it kind of bothers me that this can silently become a no-op (and in fact this is silently a no-op for all subclasses ZoneInfo). I think that the only way around it is fairly annoying if we want to allow tests to run in parallel, which is that we would need to acquire a lock around anything that deals with the cache.

__hash__ = str.__hash__

key = Stringy("America/Los_Angeles")
self.klass(key)
Copy link
Member

Choose a reason for hiding this comment

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

To increase the chance that this actually works:

Suggested change
self.klass(key)
self.klass.clear_cache(only_keys="America/Los_Angeles")
self.klass(key)

@@ -1507,6 +1530,26 @@ def test_clear_cache_two_keys(self):
self.assertIsNot(dub0, dub1)
self.assertIs(tok0, tok1)

def test_clear_cache_refleak(self):
Copy link
Member

Choose a reason for hiding this comment

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

We may also want to skip this test if self.klass is not exactly the C implementation of ZoneInfo, since otherwise it's a no-op.

@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@pganssle
Copy link
Member

pganssle commented Jul 1, 2025

Oof, missed the window for this by 12 minutes.

serhiy-storchaka added a commit that referenced this pull request Jul 1, 2025
GH-24829) (GH-136182)

(cherry picked from commit 12ce16b)

Co-authored-by: Zackery Spytz <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this pull request Jul 1, 2025
GH-24829) (GH-136181)

(cherry picked from commit 12ce16b)

Co-authored-by: Zackery Spytz <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
@serhiy-storchaka
Copy link
Member

Sorry, the PR was already on auto-merge.

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

Successfully merging this pull request may close these issues.

9 participants