Skip to content

[SR-15522] Process.run() fails with "Bad file descriptor" after a few thousand invocations. #57827

@DagAgren

Description

@DagAgren
mannequin
Previous ID SR-15522
Radar None
Original Reporter @DagAgren
Type Bug

Attachment: Download

Environment

Tested on macOS 12.0.1, Xcode 13.1 with Swift 5.5.1 as well as on Ubuntu 20.04 on an arm64 machine, again with Swift 5.5.1.

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: c5bdfb2ddbfe3ef6f3a5262fa7026ab1

Issue Description:

If you create a loop that continuously creates and runs Process objects, the run call will fail after a little while - how long seems to depend on the platform in mysterious ways, but a number of thousands typically.

The code in question also creates Pipe objects for input and output, but I have not yet tested if this affects the bug or not.

When run inside Xcode, the provided code crashes on iteration 9465. When run on the same macOS machine using swift run, it crashes on iteration 4855. When run using swift run on an arm64 Linux machine using Ubuntu 20.04, it crashes on iteration 2023.

The crash is:

Bugtest/main.swift:17: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSPOSIXErrorDomain Code=9 "Bad file descriptor"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions