I've already opened a PR for this issue, but wanted to open an issue for documenting purposes.
Copy-pasta from the PR description:
I have a Swift CLI that utilizes ShellOut to interact with binary executables. When I use shellOut too many times, I sometimes hit an exception that looks something like:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to set posix_spawn_file_actions for fd -1 at index 0 with errno 9'
*** First throw call stack:
(
0 CoreFoundation 0x00000001859672ec __exceptionPreprocess + 176
1 libobjc.A.dylib 0x000000018544e788 objc_exception_throw + 60
2 Foundation 0x0000000186a92eb4 -[NSConcreteTask launchWithDictionary:error:] + 4240
I've been able to determine this is due to the Pipe objects from ShellOut not being closed properly.
I've already opened a PR for this issue, but wanted to open an issue for documenting purposes.
Copy-pasta from the PR description:
I have a Swift CLI that utilizes ShellOut to interact with binary executables. When I use
shellOut
too many times, I sometimes hit an exception that looks something like:I've been able to determine this is due to the
Pipe
objects from ShellOut not being closed properly.I've included an example project that demonstrates the issue: NSExceptionExample.zip
Steps:
cd NSExceptionExample
swift run NSExceptionExample
ps aux | grep NSExceptionExample
and take note of the PID.lsof -p <pid> | wc -l
swift
command runs long enough, you'll hit an exception like the above.