JohnSundell / JohnSundell/ShellOut

NSInternalInconsistencyException occurs when shellOut is run too many times

Aperta
#79 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Swift
Stelle
888
Fork
87
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I've already opened a [PR](https://github.com/JohnSundell/ShellOut/pull/78) 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 included an example project that demonstrates the issue:
[NSExceptionExample.zip](https://github.com/user-attachments/files/15527111/NSExceptionExample.zip)

Steps:

1. Unzip the example library and `cd NSExceptionExample`
2. Run `swift run NSExceptionExample`
3. While that command is still running, in a separate terminal window, run `ps aux | grep NSExceptionExample` and take note of the PID.
4. Run `lsof -p | wc -l`
5. Notice how this number is quite large. Also notice that running again shows the number increasing.
6. If the `swift` command runs long enough, you'll hit an exception like the above.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia con il progetto NSExceptionExample allegato e il suo uso ripetuto di shellOut, quindi esegui `swift run NSExceptionExample` come descritto. Usa `ps` e `lsof` per osservare i descrittori di file mentre il comando è in esecuzione. Il lavoro è concluso quando le chiamate ripetute a shellOut non aumentano più costantemente il numero di descrittori aperti e non terminano con l’eccezione segnalata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
swift
Ambito
cli
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.