-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-33630: Fix race condition in TestPosixSpawn.test_open
#7663
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
|
@serhiy-storchaka Do you mind reviewing this? I am not completely happy about the code to wait for the inode to be created but I don't know if I am missing something obviously better. I am referring to this code: max_tries = 3
while not os.path.exists(outfile) and max_tries:
max_tries -= 1
time.sleep(0.1)Note: This code has changed in 28a8ced |
TestPosixSpawn.test_open
Lib/test/test_posix.py
Outdated
| os.environ, file_actions) | ||
| self.assertEqual(os.waitpid(pid, 0), (pid, 0)) | ||
|
|
||
| max_tries = 3 |
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.
For tests, I prefer to use a timeout rather than a number of tries. Like:
deadline = time.monotonic()
while 1:
if time.monotonic() > deadline: ... timeout ...
... the code ...
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.
Changed in 28a8ced
|
There is still a race condition. It is possible that the file is created, but is still empty. Relying on time is not reliable. The child can be paused at any moment. |
|
If the child is paused the |
|
Commit 1ad0a08 handles the situation in which the file is created but nothing is still written into it. |
vstinner
left a comment
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.
I would prefer to first see the posix_spawn() memory issue fixed, before fixing the Python test.
|
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 |
|
@vstinner It seems that the memory corruption is due to a bug in |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
Modules/posixmodule.c
Outdated
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.
I think the version is glibc < 2.20. It would also be nice to mention CVE-2014-4043 so later code readers could easily find out details about the glibc bug if they are interested.
zhangyangyu
left a comment
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.
My question is we should use the temp list always or just use it for glibc < 2.20? We could use macros __GLIBC__ and __GLIBC_MINOR__.
|
@zhangyangyu Done in 869dd1c |
|
I can confirm that this PR fixes both bugs. Tested on |
serhiy-storchaka
left a comment
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.
-
I think the temp list should always be used. This would make code clearer and make testing easier.
-
Make two different PRs for these changes. Changes to the test still don't LGTM.
Modules/posixmodule.c
Outdated
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.
__GLIBC__ and __GLIBC_MINOR__ give you the version of glibc used at compile time. But can not the different version be dynamically linked at run time?
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.
Yup. I updated the issue to check what people think.
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.
@serhiy-storchaka Isn't this the case for all other condition macros? For example HAVE_POSIX_SPAWN could be defined at compile time but at run time you could link to a version doesn't have posix_spawn.
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.
Perhaps you can link only to the lib with equal or larger version.
Modules/posixmodule.c
Outdated
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.
PEP 7: Add space before *, not after it.
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.
Fixed in the new PR (see comment below).
Modules/posixmodule.c
Outdated
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.
PyList_Append() can fail.
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.
Fixed in the new PR (see comment below).
|
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 |
|
@serhiy-storchaka I am going to open another PR for the changes in |
|
Created #7685 for the memory problems. This PR is only for the test race conditions. |
|
I have simplified this bugfix: As far as I understand this won't finish until the inode is created and the data is written to disk: and on the parent Unless I am missing something there is no race condition. When |
|
Let's see if the commit cb97073 fixed tests on buildbots. |
|
PPC64 Fedora 3.x, PPC64LE Fedora 3.x, s390x Debian 3.x and s390x RHEL 3.x buildbots are back to green thanks to the commit cb97073, so I don't think that this change is still needed. I close the PR. |
https://bugs.python.org/issue33630
This PR is triying to fix this error (more info in the bpo):