Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DagAgren mannequin opened this issue Nov 25, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@DagAgren
Copy link
Mannequin

DagAgren mannequin commented Nov 25, 2021

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"

@DagAgren
Copy link
Mannequin Author

DagAgren mannequin commented Nov 25, 2021

Hmm, adding this line to the end of the loop seems to resolve the issue:

try! output.fileHandleForReading.close()

This explains the bug, as it would just be a case of running out of file descriptors. However, the documentation explicitly states:

You don’t need to send closeFile() to this object or explicitly release the object after you have finished using it.

(https://developer.apple.com/documentation/foundation/pipe/1414352-filehandleforreading)

So I guess there is still an issue here, either in the implementation of Pipe or in the documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

0 participants