summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-03-20 19:40:18 (GMT)
committerAntoine Pitrou <pitrou@free.fr>2018-03-20 19:40:18 (GMT)
commitf3e6eadbcf4f3e0fe53f4784485b1c8464c7d282 (patch)
tree9b277c0729ada9ae3ee34570f8e3a882e5b816be /Python
parent424f3dafea16fbaee55a30903af2d6717f4d4a6b (diff)
downloadcpython-f3e6eadbcf4f3e0fe53f4784485b1c8464c7d282.zip
cpython-f3e6eadbcf4f3e0fe53f4784485b1c8464c7d282.tar.gz
cpython-f3e6eadbcf4f3e0fe53f4784485b1c8464c7d282.tar.bz2
[3.6] bpo-33021: Release the GIL during fstat() calls (GH-6019) (GH-6160)
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() (cherry picked from commit 4484f9dca9149da135bbae035f10a50d20d1cbbb) Co-authored-by: Nir Soffer <nirsof@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/random.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Python/random.c b/Python/random.c
index e0ee153..c62cbeb 100644
--- a/Python/random.c
+++ b/Python/random.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,