Mercurial > cpython-lru_cache-weakref
diff Modules/selectmodule.c @ 85283:a4091c1de27a 2.7
Issue #8865: Concurrent invocation of select.poll.poll() now raises a
RuntimeError exception. Patch by Christian Schubert.
| author | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| date | Tue, 20 Aug 2013 20:38:21 +0300 |
| parents | c6c2b216bd14 |
| children | 8eac75276e5b |
line wrap: on
line diff
--- a/Modules/selectmodule.c Tue Aug 20 20:08:53 2013 +0300 +++ b/Modules/selectmodule.c Tue Aug 20 20:38:21 2013 +0300 @@ -318,6 +318,7 @@ int ufd_uptodate; int ufd_len; struct pollfd *ufds; + int poll_running; } pollObject; static PyTypeObject poll_Type; @@ -513,16 +514,27 @@ return NULL; } + /* Avoid concurrent poll() invocation, issue 8865 */ + if (self->poll_running) { + PyErr_SetString(PyExc_RuntimeError, + "concurrent poll() invocation"); + return NULL; + } + /* Ensure the ufd array is up to date */ if (!self->ufd_uptodate) if (update_ufd_array(self) == 0) return NULL; + self->poll_running = 1; + /* call poll() */ Py_BEGIN_ALLOW_THREADS poll_result = poll(self->ufds, self->ufd_len, timeout); Py_END_ALLOW_THREADS + self->poll_running = 0; + if (poll_result < 0) { PyErr_SetFromErrno(SelectError); return NULL; @@ -599,6 +611,7 @@ array pointed to by ufds matches the contents of the dictionary. */ self->ufd_uptodate = 0; self->ufds = NULL; + self->poll_running = 0; self->dict = PyDict_New(); if (self->dict == NULL) { Py_DECREF(self);
