You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Code/Framework
Chris Burel ab86c9961e
[Linux] Fix deadlock when running `LaunchProcess()` from a thread (#4833)
`LaunchProcess()` on Linux works by calling `fork` then `execvpe`. `fork`
is used to copy a running process, generating a new child process. The new
child starts running from the location where the parent was running, from
whatever thread from the parent called `fork`. The child process only gets
one thread, however. If a different thread in the parent process had locked
a mutex, that mutex is also locked in the child process. Since that
separate thread is not present in the child, the mutex remains locked in
the child, with no way to unlock it. So it is important that as little work
as possible happens between the call to `fork` and to `execvpe`.

Previously, this code was trying to report an error that may have occurred
from calling `execvpe`. It was doing that by calling `AZ_TracePrintf`. That
function does lots of things, including trying to make an EBus call, which
looks up a variable in the `AZ::Environment` instance, which has a global
mutex. If there was some other thread that had that mutex locked when the
`fork` call was made, the subprocess would deadlock, and the parent process
would also deadlock waiting for the child to finish.

This solves that issue by removing the call to `AZ_TracePrintf` from the
subprocess code path. Instead, the parent process sets up a pipe for the
child process to write to in case the call to `execvpe` fails (the
self-pipe trick). The parent then reads from that pipe. If it reads no
data, `execvpe` worked and there's no error. If it does read data, the data
to be read is the errno from the failed `execvpe` call made by the child.
The parent can then use `strerror()` to report the error.

Fixes #4702.

Signed-off-by: Chris Burel <burelc@amazon.com>
4 years ago
..
AtomCore Adding a temporary Orphan function to the InstanceDatabase (#4297) 4 years ago
AzAndroid/java/com/amazon Shorten copyright headers by splitting into 2 lines (#2213) 4 years ago
AzCore Switch stacktrace output to use Output function instead of AZ_Printf to avoid it being suppressed accidentally (#4805) 4 years ago
AzFramework [Linux] Fix deadlock when running `LaunchProcess()` from a thread (#4833) 4 years ago
AzGameFramework Various updates to get pak builds working (#4552) 4 years ago
AzManipulatorTestFramework More fixes 4 years ago
AzNetworking Remove extra new lines 4 years ago
AzQtComponents Move Qt Toast Notifications from GraphCanvas into Framework 4 years ago
AzTest Merge branch 'development' into issues/exception_handling 4 years ago
AzToolsFramework Remove prefab WIP checks to make focus mode the default (and only) prefab editing workflow in the editor. (#4840) 4 years ago
GFxFramework More fixes 4 years ago
GridMate Remove old "Integ" functionality from tests (#4688) 4 years ago
CMakeLists.txt Remove crcfix (#3294) 4 years ago