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.

Title: off-by-one error when listing /proc/self/fd/
Type: Stage: resolved
Components: Tests Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, pitrou, vstinner
Priority: normal Keywords: patch

Created on 2018-06-05 11:29 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7421 merged vstinner, 2018-06-05 11:31
PR 7454 merged miss-islington, 2018-06-06 15:26
PR 7455 merged miss-islington, 2018-06-06 15:27
PR 7456 merged vstinner, 2018-06-06 15:48
Messages (6)
msg318734 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-05 11:29 has two implementation: list /proc/self/fd/ on Linux and FreeBSD, or check all file descriptors from 0 and MAXFD. The problem is that the two implementation don't give the same result...

List /proc/self/fd/ (used by default on Linux):

vstinner@apu$ ./python -c 'from import fd_count; print(fd_count())'

Check all FD (I modified fd_count() to force using this implementation):

vstinner@apu$ ./python -c 'from import fd_count; print(fd_count())'

On Linux and FreeBSD, listdir() opens internally a file descriptor to list the content of the /proc/self/fd/ directory. So the function should substract one to the result.

Attached PR fixes the issue.
msg318736 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-05 11:32
fd_count() has been added by bpo-18174. I just backported it to Python 2.7 to check for leak of file descriptors in tests. I found the bug when I fixed a bug on Python 2.7 on FreeBSD.
msg318834 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-06 15:23
New changeset 492d6424a7ca907c8ec1df21e51062e8f3d88e32 by Victor Stinner in branch 'master':
bpo-33773: Fix on Linux/FreBSD (GH-7421)
msg318841 - (view) Author: miss-islington (miss-islington) Date: 2018-06-06 15:57
New changeset 016aff77cbf5f63ed051a98ac628522a1cfd40a4 by Miss Islington (bot) in branch '3.7':
bpo-33773: Fix on Linux/FreBSD (GH-7421)
msg318843 - (view) Author: miss-islington (miss-islington) Date: 2018-06-06 16:09
New changeset 97fe1b493df979956c66c57095bc7fce22104faf by Miss Islington (bot) in branch '3.6':
bpo-33773: Fix on Linux/FreBSD (GH-7421)
msg318849 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-06 17:05
New changeset 67b7158d53f33ed644cc11ef394470a859ea8bad by Victor Stinner in branch '2.7':
bpo-33773: Fix on Linux/FreBSD (GH-7421) (GH-7456)
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 77954
2018-06-06 17:05:16vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-06-06 17:05:00vstinnersetmessages: + msg318849
2018-06-06 16:09:28miss-islingtonsetmessages: + msg318843
2018-06-06 15:57:22miss-islingtonsetnosy: + miss-islington
messages: + msg318841
2018-06-06 15:48:37vstinnersetpull_requests: + pull_request7079
2018-06-06 15:27:37miss-islingtonsetpull_requests: + pull_request7078
2018-06-06 15:26:42miss-islingtonsetpull_requests: + pull_request7077
2018-06-06 15:23:52vstinnersetmessages: + msg318834
2018-06-05 11:32:01vstinnersetmessages: + msg318736
2018-06-05 11:31:17vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request7046
2018-06-05 11:29:39vstinnercreate