python / python/cpython

Importing ctypes results in extra open libffi file descriptor since 3.14

Open
#135,893 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules topic-ctypes type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

On python 3.13 (Fedora), importing ctypes results in the following output from lsfd:

python3 893377 daandemeyer    mem r-x---  REG   0:37     0  304862113 /usr/lib64/libffi.so.8.1.4
python3 893377 daandemeyer    mem r-----  REG   0:37     0  304862113 /usr/lib64/libffi.so.8.1.4
python3 893377 daandemeyer    mem r-----  REG   0:37     0  304862113 /usr/lib64/libffi.so.8.1.4
python3 893377 daandemeyer    mem rw----  REG   0:37     0  304862113 /usr/lib64/libffi.so.8.1.4

On python 3.14 (Fedora), importing ctypes results in the following output from lsfd:

python3 892407 daandemeyer      5 r-----  REG  0:238  1342       7553 /usr/lib64/libffi.so.8.2.0

This ended up breaking https://github.com/systemd/mkosi because it relied on the fact that no new regular file descriptors were opened by importing ctypes (on python 3.14 the file descriptor shows up in /proc/self/fd whereas on python 3.13 the file descriptors are memory maps which don't show up in /proc/self/fd). I searched through the commit list and couldn't find the commit that introduced this change. It also didn't seem to be documented in the release notes. Can anyone point me to the commit introducing this change and the reasoning behind it?

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing ctypes imports on Python 3.13 and 3.14 on Linux, using lsfd and /proc/self/fd as in the report. Trace the CPython commit history for the change that makes libffi appear as a regular file descriptor, then determine its rationale and whether the behavior requires a regression fix or release-note documentation. Done means the change and reasoning are clearly identified and verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.