You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
In particular, there's an unsynchronised, shared variable running that's read and written to from multiple threads. That is undefined behaviour which might amongst random crashes, infinite while running loops (even if running gets set to false) might lead to arbitrary worse behaviour.
This can easily be fixed by using a lock around every use of running. But I'd recommend restructuring the code. At present it keeps three background threads blocked for every execution of a process. Worse, because Dispatch normally uses a finitely sized thread-pool this code might just randomly deadlock. The reason it might randomly deadlock is that it will only finish when this code is executed:
But the promise.succeed is inside of a globalQueue.async which needs an available dispatch thread to run. And while it waits for that dispatch thread to become available it blocks to others (to read stderr and stdout). In other words: We need three available dispatch threads to make progress which is an anti-pattern in Dispatch because the thread pool has a finite number of threads so it can totally happen that all of Dispatch's threads are blocked and only become unblocked when more threads become available (which won't happen if the thread pool is exhausted).
The text was updated successfully, but these errors were encountered:
Process.asyncExecute
contains this code:core/Sources/Core/Process+Execute.swift
Lines 99 to 117 in 96ce86e
In particular, there's an unsynchronised, shared variable
running
that's read and written to from multiple threads. That is undefined behaviour which might amongst random crashes, infinitewhile running
loops (even ifrunning
gets set to false) might lead to arbitrary worse behaviour.This can easily be fixed by using a lock around every use of
running
. But I'd recommend restructuring the code. At present it keeps three background threads blocked for every execution of a process. Worse, becauseDispatch
normally uses a finitely sized thread-pool this code might just randomly deadlock. The reason it might randomly deadlock is that it will only finish when this code is executed:core/Sources/Core/Process+Execute.swift
Lines 135 to 139 in 96ce86e
But the
promise.succeed
is inside of aglobalQueue.async
which needs an available dispatch thread to run. And while it waits for that dispatch thread to become available it blocks to others (to readstderr
andstdout
). In other words: We need three available dispatch threads to make progress which is an anti-pattern in Dispatch because the thread pool has a finite number of threads so it can totally happen that all of Dispatch's threads are blocked and only become unblocked when more threads become available (which won't happen if the thread pool is exhausted).The text was updated successfully, but these errors were encountered: