Skip to content

mitogen: Only close stdio file descriptors that were open at process startup - #1268

Merged
moreati merged 12 commits into
mitogen-hq:masterfrom
moreati:stdio-no-no-no
May 29, 2025
Merged

mitogen: Only close stdio file descriptors that were open at process startup#1268
moreati merged 12 commits into
mitogen-hq:masterfrom
moreati:stdio-no-no-no

Conversation

@moreati

@moreati moreati commented May 29, 2025

Copy link
Copy Markdown
Member

File descriptors 0, 1, and 2 are usually stdin, stdout, stderr; but not always. If a process is started without one of these then the first descriptor allocated by the process opening a file or socket will be allocated an fd <= STDERR_FILENO. This isn't common, but it does occur, e.g. Windows GUI apps started without being connected to a console, controller side plugins run under Ansible 12 (ansible-core 2.19).

In such cases the corresponding sys attribute (e.g. sys.stderr) will be None.

This PR is in preparation of Ansible 12 (ansible-core 2.19). During development Mitogen was hanging or closing the connection early with ansible-core 2.19.0a and 2.19.0b releases. The cause was Mitogen incorrectly closing its own sockets and pipes, because they had an fd <= 3.

See #1258, #1259

See also

moreati added 12 commits May 29, 2025 11:44
This eliminates the need for ansible_facts to be gathered before
become_unpriv_available can be referenced.
…ed`)

Required by Ansible 12 (ansible-core-2.19).

refs mitogen-hq#1298
…ybook

This makes the behaviour more consistent across jobs that run with
`mitogen_linear` or plain `linear`.
The Van_* GitHub Actions jobs (corresponding to Tox factor strategy_linear,
environment variable ANSIBLE_STRATEGY=linear) were failing inside Mitogen
modules, which they should not touch. The jobs are intended as a cross
validation of the test suite, they should only fail if Ansible itself has a
problem.
Simplifies matching a failed test to the play/task.
Some tests have been seen deadlocked. They continued running for an hour+,
until the default Github timeout. Linux timeout higher than macOS because the
Linux jobs run more tests.
Makes it more obvious and easier to find where stdin, stdout, and stderr file
descriptors are being interacted with.
…startup

File descriptors 0, 1, and 2 are usually stdin, stdout, stderr; but not
always. If a process is started without one of these then the first descriptor
allocated by the process opening a file or socket will be allocated an fd <=
STDERR_FILENO. This isn't common, but it does occur, e.g. Windows GUI apps
started without being connected to a console, controller side plugins run
under Ansible 12 (ansible-core 2.19).

In such cases the corresponding sys attribute (e.g. sys.stderr) will be None.

refs mitogen-hq#1258

See also
- https://docs.python.org/3/library/sys.html#sys.__stdin__
- https://docs.ansible.com/ansible/devel/porting_guides/porting_guide_12.html#porting-guide-for-v12-0-0a1
- ansible/ansible#82770
- python/typeshed#11778
- https://gist.github.com/moreati/034fef45f73d809d9411a8a63eca34d6
The repr() of file objects is more self descriptive, and includes the fd.
@moreati
moreati marked this pull request as ready for review May 29, 2025 11:52
@moreati
moreati merged commit 07028c1 into mitogen-hq:master May 29, 2025
@moreati
moreati deleted the stdio-no-no-no branch May 29, 2025 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant