Skip to content

tests: simulated terminals leak into commands that other tests start #15216

Closed

Description

@abendrothj

The PTYs behind UCommand::terminal_simulation are opened with openpty, which doesn't set close-on-exec. While a test with a simulated terminal runs, every command another test thread starts inherits them, up to six descriptors.

That breaks tests that run under a low descriptor limit. On #15135, test_temporary_files_with_few_file_descriptors failed twice on the aarch64 Linux job: with the inherited descriptors, sort can't start gzip under a limit of 10 (log). With one thread running terminal-simulated commands, 275 of 300 commands started by another thread inherited PTY descriptors.

Two ways to fix it:

  1. Open the PTY close-on-exec from the start where the OS supports it (Linux, Android, FreeBSD, NetBSD, through rustix), and set it right after openpty elsewhere. This closes the race on those systems.
  2. Simpler: set close-on-exec right after openpty everywhere. That leaves a short window; in a tight loop 2 to 5 of 300 commands still inherited them.

Either way the harness has to keep the stdin PTY open until the child exits. Today that only works because the child inherits a copy of it.

Activity

  1. abendrothj commented on Oct 10, 2026

    @abendrothj
    ContributorAuthor

    Reproduced locally (Linux, aarch64): sort's -S 64K --compress-program gzip under a limit of 10, while 4 threads run terminal-simulated commands, failed 6 of 200 times with could not run compress program 'gzip': Too many open files. With #15217 applied it failed 0 of 200. With only 1 terminal thread it didn't fail, since too few descriptors leak at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions