-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-35189: Retry fnctl calls on EINTR #10413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2018-11-09-13-35-36.bpo-35189.gog-sl.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Modify the following fnctl function to retry if interrupted by a signal | ||
(EINTR): flock, lockf, fnctl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) | |
char *str; | ||
Py_ssize_t len; | ||
char buf[1024]; | ||
int async_err = 0; | ||
|
||
if (arg != NULL) { | ||
int parse_result; | ||
|
@@ -75,12 +76,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) | |
return NULL; | ||
} | ||
memcpy(buf, str, len); | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, code, buf); | ||
Py_END_ALLOW_THREADS | ||
do { | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, code, buf); | ||
Py_END_ALLOW_THREADS | ||
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||
if (ret < 0) { | ||
PyErr_SetFromErrno(PyExc_OSError); | ||
return NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is something that I do not understand, why before result of PyErr_SetFromErrno(PyExc_OSError) was not returned. The new code is in sync with other modules, now. /repeats |
||
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; | ||
} | ||
return PyBytes_FromStringAndSize(buf, len); | ||
} | ||
|
@@ -95,12 +97,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) | |
} | ||
} | ||
|
||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, code, (int)int_arg); | ||
Py_END_ALLOW_THREADS | ||
do { | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, code, (int)int_arg); | ||
Py_END_ALLOW_THREADS | ||
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||
if (ret < 0) { | ||
PyErr_SetFromErrno(PyExc_OSError); | ||
return NULL; | ||
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; | ||
} | ||
return PyLong_FromLong((long)ret); | ||
} | ||
|
@@ -283,11 +286,14 @@ fcntl_flock_impl(PyObject *module, int fd, int code) | |
/*[clinic end generated code: output=84059e2b37d2fc64 input=b70a0a41ca22a8a0]*/ | ||
{ | ||
int ret; | ||
int async_err = 0; | ||
|
||
#ifdef HAVE_FLOCK | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = flock(fd, code); | ||
Py_END_ALLOW_THREADS | ||
do { | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = flock(fd, code); | ||
Py_END_ALLOW_THREADS | ||
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||
#else | ||
|
||
#ifndef LOCK_SH | ||
|
@@ -310,14 +316,15 @@ fcntl_flock_impl(PyObject *module, int fd, int code) | |
return NULL; | ||
} | ||
l.l_whence = l.l_start = l.l_len = 0; | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l); | ||
Py_END_ALLOW_THREADS | ||
do { | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l); | ||
Py_END_ALLOW_THREADS | ||
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||
} | ||
#endif /* HAVE_FLOCK */ | ||
if (ret < 0) { | ||
PyErr_SetFromErrno(PyExc_OSError); | ||
return NULL; | ||
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; | ||
} | ||
Py_RETURN_NONE; | ||
} | ||
|
@@ -363,6 +370,7 @@ fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj, | |
/*[clinic end generated code: output=4985e7a172e7461a input=3a5dc01b04371f1a]*/ | ||
{ | ||
int ret; | ||
int async_err = 0; | ||
|
||
#ifndef LOCK_SH | ||
#define LOCK_SH 1 /* shared lock */ | ||
|
@@ -407,13 +415,14 @@ fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj, | |
return NULL; | ||
} | ||
l.l_whence = whence; | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l); | ||
Py_END_ALLOW_THREADS | ||
do { | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l); | ||
Py_END_ALLOW_THREADS | ||
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); | ||
} | ||
if (ret < 0) { | ||
PyErr_SetFromErrno(PyExc_OSError); | ||
return NULL; | ||
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; | ||
} | ||
Py_RETURN_NONE; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a race condition that is kind of shared with all other tests in this file. We can not make sure that the function really blocked at least for some time. The race condition would be exposed under heavy load in which the main process was not given resources for at least self.sleep_time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are run sequentially, so it's not an issue. Moreover, regrtest ensures that TESTFN is unique between two working processes running Python tests.