classification
Title: [FreeBSD, OSX] Socket module: incorrect usage of poll(2)
Type: Stage: resolved
Components: FreeBSD, IO, Library (Lib), macOS Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: akhramov, koobs, miss-islington, ned.deily, ronaldoussoren, shihai1991, vstinner
Priority: normal Keywords: patch

Created on 2019-08-10 20:29 by akhramov, last changed 2019-08-14 22:38 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
connect_eintr.py akhramov, 2019-08-10 20:29 Repro
Pull Requests
URL Status Linked Edit
PR 15202 merged akhramov, 2019-08-10 20:32
PR 15289 merged miss-islington, 2019-08-14 21:22
PR 15290 merged miss-islington, 2019-08-14 21:22
Messages (8)
msg349356 - (view) Author: Artem Khramov (akhramov) * Date: 2019-08-10 20:29
FreeBSD implementation of poll(2) restricts timeout argument to be either zero, or positive, or equal to INFTIM (-1).

Unless otherwise overridden, socket timeout defaults to -1. This value is then converted to milliseconds (-1000) and used as argument to the poll syscall.

poll returns EINVAL (22), and the connection fails.

I have discovered this bug during the EINTR handling testing, and have naturally found a repro code in https://bugs.python.org/issue23618 (see connect_eintr.py, attached). On GNU/Linux, the example runs as expected.
msg349382 - (view) Author: hai shi (shihai1991) * Date: 2019-08-11 09:42
I found an OS distinguishing behavior in https://github.com/python/cpython/blob/master/Modules/selectmodule.c#L603-L612
msg349383 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2019-08-11 09:47
See Also: #31334
msg349753 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-08-14 21:18
> See Also: #31334

Oh, I didn't know bpo-31334. This issue is basically a duplicate of bpo-31334, but triggered differently.
msg349754 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-08-14 21:21
New changeset 28146206578ebe1b84b48e6f255738a227058c04 by Victor Stinner (Artem Khramov) in branch 'master':
bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202)
https://github.com/python/cpython/commit/28146206578ebe1b84b48e6f255738a227058c04
msg349760 - (view) Author: miss-islington (miss-islington) Date: 2019-08-14 21:47
New changeset 123f6c4914827c4ced65d032fab74de62db31cd6 by Miss Islington (bot) in branch '3.8':
bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202)
https://github.com/python/cpython/commit/123f6c4914827c4ced65d032fab74de62db31cd6
msg349761 - (view) Author: miss-islington (miss-islington) Date: 2019-08-14 21:48
New changeset b0b178a2b80974da910ce6a344d66cc4d9a2fcfa by Miss Islington (bot) in branch '3.7':
bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202)
https://github.com/python/cpython/commit/b0b178a2b80974da910ce6a344d66cc4d9a2fcfa
msg349772 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-08-14 22:38
Thanks Artem Khramov for the nice analysis of the root issue! And thanks for the fix! The bug is now fixed in 3.7, 3.8 and master branches.

Python 2.7 is not affected: I added sock_call_ex() helper function in Python 3 when I implemeneted the PEP 475 (Retry system calls failing with EINTR).
History
Date User Action Args
2019-08-14 22:38:37vstinnersetstatus: open -> closed
versions: - Python 2.7, Python 3.5, Python 3.6
messages: + msg349772

resolution: fixed
stage: patch review -> resolved
2019-08-14 21:48:07miss-islingtonsetmessages: + msg349761
2019-08-14 21:47:49miss-islingtonsetnosy: + miss-islington
messages: + msg349760
2019-08-14 21:22:21miss-islingtonsetpull_requests: + pull_request15014
2019-08-14 21:22:15miss-islingtonsetpull_requests: + pull_request15013
2019-08-14 21:21:52vstinnersetmessages: + msg349754
2019-08-14 21:18:25vstinnersetnosy: + vstinner
messages: + msg349753
2019-08-14 03:22:20akhramovsetnosy: + ned.deily, ronaldoussoren
components: + Library (Lib), macOS, IO, FreeBSD
2019-08-11 09:47:38koobssetmessages: + msg349383
2019-08-11 09:43:58koobssetnosy: + koobs
2019-08-11 09:42:12shihai1991setnosy: + shihai1991
messages: + msg349382
2019-08-10 20:32:19akhramovsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14931
2019-08-10 20:29:31akhramovcreate