diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-12-01 06:26:31 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-12-01 06:26:31 (GMT) |
commit | 8bcd41040a5f1f9b48a86d0e21f196e4b1f90e4b (patch) | |
tree | 11a56145f0c96232e9067ab3bdcba5bb6d469da0 /Modules | |
parent | e10c9de9d74fd4c26b32e6719d96f04a5be6987d (diff) | |
download | cpython-8bcd41040a5f1f9b48a86d0e21f196e4b1f90e4b.zip cpython-8bcd41040a5f1f9b48a86d0e21f196e4b1f90e4b.tar.gz cpython-8bcd41040a5f1f9b48a86d0e21f196e4b1f90e4b.tar.bz2 |
bpo-32186: Release the GIL during lseek and fstat (GH-4652) (#4661)
In _io_FileIO_readall_impl(), lseek() and _Py_fstat_noraise() were called
without releasing the GIL. This can cause all threads to hang for
unlimited time when calling FileIO.read() and the NFS server is not
accessible.
(cherry picked from commit 6a89481680b921e7b317c29877bdda9a6031e5ad)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/fileio.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 918fa57..52cbb94 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -691,10 +691,12 @@ _io_FileIO_readall_impl(fileio *self) Py_ssize_t bytes_read = 0; Py_ssize_t n; size_t bufsize; + int fstat_result; if (self->fd < 0) return err_closed(); + Py_BEGIN_ALLOW_THREADS _Py_BEGIN_SUPPRESS_IPH #ifdef MS_WINDOWS pos = _lseeki64(self->fd, 0L, SEEK_CUR); @@ -702,8 +704,10 @@ _io_FileIO_readall_impl(fileio *self) pos = lseek(self->fd, 0L, SEEK_CUR); #endif _Py_END_SUPPRESS_IPH + fstat_result = _Py_fstat_noraise(self->fd, &status); + Py_END_ALLOW_THREADS - if (_Py_fstat_noraise(self->fd, &status) == 0) + if (fstat_result == 0) end = status.st_size; else end = (Py_off_t)-1; |