summaryrefslogtreecommitdiffstats
path: root/Modules/mmapmodule.c
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 /Modules/mmapmodule.c
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 'Modules/mmapmodule.c')
-rw-r--r--Modules/mmapmodule.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 6cf4545..6abdc71 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1050,6 +1050,7 @@ static PyObject *
new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
{
struct _Py_stat_struct status;
+ int fstat_result;
mmap_object *m_obj;
Py_ssize_t map_size;
off_t offset = 0;
@@ -1115,8 +1116,14 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
if (fd != -1)
(void)fcntl(fd, F_FULLFSYNC);
#endif
- if (fd != -1 && _Py_fstat_noraise(fd, &status) == 0
- && S_ISREG(status.st_mode)) {
+
+ if (fd != -1) {
+ Py_BEGIN_ALLOW_THREADS
+ fstat_result = _Py_fstat_noraise(fd, &status);
+ Py_END_ALLOW_THREADS
+ }
+
+ if (fd != -1 && fstat_result == 0 && S_ISREG(status.st_mode)) {
if (map_size == 0) {
if (status.st_size == 0) {
PyErr_SetString(PyExc_ValueError,