mirror of
https://github.com/python/cpython.git
synced 2025-09-29 19:56:59 +00:00
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 6a89481680
)
This commit is contained in:
parent
e10c9de9d7
commit
8bcd41040a
2 changed files with 8 additions and 1 deletions
|
@ -0,0 +1,3 @@
|
|||
io.FileIO.readall() and io.FileIO.read() now release the GIL when
|
||||
getting the file size. Fixed hang of all threads with inaccessible NFS
|
||||
server. Patch by Nir Soffer.
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue