summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorNir Soffer <nirsof@gmail.com>2018-03-11 23:39:22 (GMT)
committerAntoine Pitrou <pitrou@free.fr>2018-03-11 23:39:22 (GMT)
commit4484f9dca9149da135bbae035f10a50d20d1cbbb (patch)
tree3caa068402965d1f8a14407ea7b09fda5902ffbf /Python
parente756f66c83786ee82f5f7d45931ae50a6931dd7f (diff)
downloadcpython-4484f9dca9149da135bbae035f10a50d20d1cbbb.zip
cpython-4484f9dca9149da135bbae035f10a50d20d1cbbb.tar.gz
cpython-4484f9dca9149da135bbae035f10a50d20d1cbbb.tar.bz2
bpo-33021: Release the GIL during fstat() calls (GH-6019)
fstat may block for long time if the file descriptor is on a non-responsive NFS server, hanging all threads. Most fstat() calls are handled by _Py_fstat(), releasing the GIL internally, but but _Py_fstat_noraise() does not release the GIL, and most calls release the GIL explicitly around it. This patch fixes last 2 calls to _Py_fstat_no_raise(), avoiding hangs when calling: - mmap.mmap() - os.urandom() - random.seed()
Diffstat (limited to 'Python')
-rw-r--r--Python/bootstrap_hash.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c
index 9fd5cfb..073b2ea 100644
--- a/Python/bootstrap_hash.c
+++ b/Python/bootstrap_hash.c
@@ -301,10 +301,15 @@ dev_urandom(char *buffer, Py_ssize_t size, int raise)
if (raise) {
struct _Py_stat_struct st;
+ int fstat_result;
if (urandom_cache.fd >= 0) {
+ Py_BEGIN_ALLOW_THREADS
+ fstat_result = _Py_fstat_noraise(urandom_cache.fd, &st);
+ Py_END_ALLOW_THREADS
+
/* Does the fd point to the same thing as before? (issue #21207) */
- if (_Py_fstat_noraise(urandom_cache.fd, &st)
+ if (fstat_result
|| st.st_dev != urandom_cache.st_dev
|| st.st_ino != urandom_cache.st_ino) {
/* Something changed: forget the cached fd (but don't close it,