➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: PEP 475: os.urandom() doesn't handle EINTR correctly
类型: Stage:
Components: Versions: Python 3.5
process
状态: closed Resolution: fixed
Dependencies: 23708 后续:
分配给: 抄送列表: neologix, python-dev, vstinner
优先级: normal 关键字: patch

Created on 2015-03-19 12:19 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

文件
文件名 上传时间 Description 编辑
random.patch vstinner, 2015-03-19 13:38 review
Messages (3)
msg238503 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2015-03-19 12:19
dev_urandom_python() retries read() if it fails with EINTR, but Python signal handlers are not called: PyErr_CheckSignals() is not called. It's important be able to interrupt a function by a signal, especially if it's blocking.

We need maybe a new _Py_read() function which would retry on EINTR. The code can be based on posix_read(). For open(), there is already _Py_open() which retries on EINTR (since the changeset ed25e945cdc2, issue #23694). It can be useful for FileIO.read().

dev_urandom_noraise() retries on EINTR without calling PyErr_CheckSignals(). It may be acceptable since this function is only called by _PyRandom_Init() at an early stage of Python initialization. Or maybe EINTR should call Py_FatalError()?

On Linux 3.18 (Fedora 21 with kernel 3.18.7-200.fc21.x86_64), reading 1 GB from /dev/urandom or getrandom() returns 0x1ffffff bytes (32 MB). It's not an issue, os.urandom() continues to read until it gets enough data.

I tried to interrupt os.urandom() on Python 3.4 (read) and Python 3.5 (getrandom): reading from /dev/urandom using a file descriptor or getrandom() have the same behaviour, none fail with EINTR. I checked syscalls using strace.

It looks like getrandom() only fails with EINTR when flags=GRND_RANDOM. So this issue is maybe more theoric.
msg238519 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 2015-03-19 13:38
random.patch: fix the issue with the new _Py_read() function added by the issue #23708.
msg238574 - (view) Author: Roundup Robot (python-dev) (Python triager) 日期: 2015-03-19 22:43
New changeset e57b4d464d1c by Victor Stinner in branch 'default':
Issue #23707: On UNIX, os.urandom() now calls the Python signal handler when
https://hg.python.org/cpython/rev/e57b4d464d1c
历史
日期 用户 动作 参数
2022-04-11 14:58:14admin修改github: 67895
2015-03-19 22:44:11vstinner修改状态: open -> closed
resolution: fixed
2015-03-19 22:43:59python-dev修改抄送: + python-dev
消息: + msg238574
2015-03-19 20:20:53ned.deily修改抄送: + neologix
2015-03-19 13:41:20vstinner链接issue23648 dependencies
2015-03-19 13:38:08vstinner修改文件: + random.patch
keywords: + patch
dependencies: + PEP 475: Add _Py_read() and _Py_write() functions
消息: + msg238519
2015-03-19 12:19:55vstinner创建