From 1258ef46524b65fab0ef5c2d61737d23d334436a Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Thu, 30 Nov 2017 19:22:18 +0200 Subject: [PATCH 1/3] bpo-32186: Release the GIL during lseek and fstat 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. --- Modules/_io/fileio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index b6755b851dca8ed..269142cfee5242c 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -683,10 +683,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); @@ -694,8 +696,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; From ffd6f44f08ec0e8255b4724c8904bc9c0a3a32d9 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Thu, 30 Nov 2017 20:38:25 +0200 Subject: [PATCH 2/3] Add news entry --- .../next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst diff --git a/Misc/NEWS.d/next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst b/Misc/NEWS.d/next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst new file mode 100644 index 000000000000000..4a92f7b9b24d420 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst @@ -0,0 +1,3 @@ +Fixed hang of all threads when using io.FileIO with inaccessible NFS server. +Now only the thread accessing the problematic storage will hang. Patch by +Nir Soffer. From 4da81693a4e767d4e2e2425e49efb146d604d589 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Fri, 1 Dec 2017 00:28:21 +0200 Subject: [PATCH 3/3] Clarify the news entry - Mention the impacted methods and the GIL (Victor) --- .../next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst b/Misc/NEWS.d/next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst index 4a92f7b9b24d420..ea696c6098a1d22 100644 --- a/Misc/NEWS.d/next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst +++ b/Misc/NEWS.d/next/Library/2017-11-30-20-38-16.bpo-32186.O42bVe.rst @@ -1,3 +1,3 @@ -Fixed hang of all threads when using io.FileIO with inaccessible NFS server. -Now only the thread accessing the problematic storage will hang. Patch by -Nir Soffer. +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.