Skip to content

Conversation

@tjguk
Copy link
Member

@tjguk tjguk commented Oct 25, 2021

bpo-40915: Fix mmap resize bugs on Windows

The current implementation of mmap.resize on Windows contains several subtle bugs. This PR, principally using code contributed by eryksun, addresses those bugs and adds corresponding tests.

I've added some doc changes, but I'm not convinced that they should go in, since the cases addressed are relatively niche.

https://bugs.python.org/issue40915

… an exception but retains the mapping

Remove the specific pre-check on resizing a named section but specifically account for it later when resizing
@tjguk tjguk changed the title bpo-40915: Fix mmap resize bugs on Windows bpo-40915: Fix mmap resize bugs on Windows (GH-29213) Oct 25, 2021
Copy link
Member

@zooba zooba left a comment

Choose a reason for hiding this comment

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

Nice change. I still have a couple more questions, but if you're happy with your answers, don't wait on me before merging.

@tjguk tjguk merged commit aea5ecc into python:main Oct 26, 2021
@tjguk tjguk deleted the issue40915-mmap-resize branch October 26, 2021 21:56
"""
start_size = 2 * PAGESIZE
reduced_size = PAGESIZE
tagname = "TEST"
Copy link
Contributor

@eryksun eryksun Oct 27, 2021

Choose a reason for hiding this comment

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

I'm sorry to have missed this before you merged. Naming kernel objects with generic names like "foo" and "TEST" is a bad idea because the namespace is shared by every process in the current session. It's a serious problem in all of the tests that use tagname. If the name is an existing Section object (i.e. file mapping), CreateFileMapping() will succeed with the last error set to ERROR_ALREADY_EXISTS. In many cases, the Section object likely refers to an unrelated file, but we can't avoid this, or even know about the problem, because mmap doesn't currently support exclusive ("x") creation. This and a few other cases really need to be addressed in the constructor, but that's a separate issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @eryksun -- good catch. Funnily enough, I'm normally a little over-obsessive with test names, generating them randomly to descrease any chance of a "lucky name". This time I've gone the other way! I'll run up a quick patch to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants