Skip to content

[2.7] bpo-33021: Release the GIL during fstat() calls (GH-6019)#6020

Closed
nirs wants to merge 2 commits into
python:2.7from
nirs:fstat-gil-2.7
Closed

[2.7] bpo-33021: Release the GIL during fstat() calls (GH-6019)#6020
nirs wants to merge 2 commits into
python:2.7from
nirs:fstat-gil-2.7

Conversation

@nirs

@nirs nirs commented Mar 7, 2018

Copy link
Copy Markdown
Contributor

If the file descriptor is on a non-responsive NFS server, calling
fstat() can block for long time, hanging all threads. Most of the calls
release the GIL around the call, but some calls seems to be forgotten.

This patch fixes the last calls, affecting users of:

  • imp.load_dynamic()
  • imp.load_source()
  • mmap.mmap()
  • mmapobject.size()
  • os.fdopen()
  • os.urandom()
  • random.seed()

https://bugs.python.org/issue33021

If the file descriptor is on a non-responsive NFS server, calling
fstat() can block for long time, hanging all threads. Most of the calls
release the GIL around the call, but some calls seems to be forgotten.

This patch fixes the last calls, affecting users of:
- imp.load_dynamic()
- imp.load_source()
- mmap.mmap()
- mmapobject.size()
- os.fdopen()
- os.urandom()
- random.seed()

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As on the other PR, this looks good on the principle, but you'll need to generate a NEWS entry.

Also, since 2.7 is in maintenance mode, I'm cc'ing our release manager Benjamin to get his approval on this. @benjaminp

@bedevere-bot

Copy link
Copy Markdown

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.

@nirs

nirs commented Mar 11, 2018

Copy link
Copy Markdown
Contributor Author

Thanks for the review @pitrou! I have made the requested changes; please review again.

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@pitrou: please review the changes made to this pull request.

@pitrou

pitrou commented Mar 11, 2018

Copy link
Copy Markdown
Member

Thanks for the update. This looks good on the principle. I'll defer to @benjaminp for the backport decision.

@benjaminp

Copy link
Copy Markdown
Contributor

Releasing the GIL in new places tends to open new and exciting opportunities for reëntrancy bugs, so I'm not sure this is completely safe.

@pitrou

pitrou commented Mar 12, 2018

Copy link
Copy Markdown
Member

I'm not sure about reëntrancy bugs, but I agree there may be thread-safetÿ issues on ill-behaving platforms (though for fstat() we already release the GIL in other places).

@pitrou

pitrou commented Mar 12, 2018

Copy link
Copy Markdown
Member

Actually, you're right, I remember about someone implementing a FUSE filesystem with Python and there were interesting reëntrancy issues with GIL releasing specifics.

@pitrou

pitrou commented Mar 14, 2018

Copy link
Copy Markdown
Member

Ok, I'm closing this PR as rejected.

@pitrou pitrou closed this Mar 14, 2018
@nirs

nirs commented Mar 14, 2018

Copy link
Copy Markdown
Contributor Author

@benjaminp, we are releasing the GIL on all fstat calls in python 3. Why is this correct and safe in python 3 but no in python 2?

I'm pretty sure that not releasing the GIL is not safe. Try to mmap a file on non-responsive NFS server - do you really want the entire process to hang?

I can extract the mmap.xxx and os.fdopen changes to a separate patch, since the other changes will are much less likely to block (e.g. fstat for /dev/urandom).

@benjaminp

Copy link
Copy Markdown
Contributor

I'm not sure throwing Py_BEGIN_ALLOW_THREADS around every fstat call is any better for Python 3. Releasing the GIL around operations on /dev/urandom FDs is probably pure overhead, since no actual IO ever ends up happening.

@nirs

nirs commented Mar 17, 2018

Copy link
Copy Markdown
Contributor Author

@benjaminp I suggest to continue on the issue, I added more info there.

@nirs nirs deleted the fstat-gil-2.7 branch October 1, 2022 22:17
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.

5 participants