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

Deadlock is possible when recording is stopped #1694

Closed
yanenkoa opened this issue Jan 11, 2019 · 0 comments
Closed

Deadlock is possible when recording is stopped #1694

yanenkoa opened this issue Jan 11, 2019 · 0 comments
Assignees

Comments

@yanenkoa
Copy link
Contributor

As of writing this text, it is currently possible to run into deadlock when stopping recording thread.

In PR #1505, a new method of capturing images from cameras and cameras' positions in sync with each other was introduced: the recording thread is adding a delegate function to call on a GameThread whenever drawing ends (UGameViewportClient::OnEndDraw). This code is in Unreal/Plugins/AirSim/Source/RenderRequest.cpp.

Problems begin when we want to stop the recording. This is done by calling FRecordingThread::stopRecording, which calls FRecordingThread::EnsureCompletion, which sends a signal to recording thread to stop execution and then waits for it to actually finish.

FRecordingThread::stopRecording is always called in the GameThread. So whenever it is called, GameThread starts waiting for FRecordingThread to finish. The issue is, FRecordingThread can be waiting for drawing to end, and drawing is happening on a GameThread. So the situation is possible, when GameThread is waiting for FRecordingThread to finish, while FRecordingThread is waiting for a specific event on the GameThread to fire — a deadlock.

The result is, obviously enough, that UE4 app freezes completely and stops reacting to any sort of input and can only be closed by killing the process. In our project, we start and stop recording programmatically in an endless loop, so it's only a matter of time when this occurs and the simulation needs to be restarted manually. This can also occur when Play-In-Editor session is interrupted by pressing "Stop" button from inside UE4 editor or when exit command is executed in UE4 console.

Admittedly, AirSim architecture does not seem to be designed with this in mind, because stopRecording is not exposed to the code outside AirSim. We get around this by firing USimHUDWidget::onToggleRecordingButtonClick on USimHUDWidget instance in blueprints (simulating a button press on the "Toggle Recording" button in the lower right corner).

The problem is kind of hard to reproduce by its nature. However, if you load a heavy enough map in UE4, set RecordInterval very low (0.1, for instance), and start and stop recording in an endless loop (for example, starting a recording, waiting for 3 seconds, stopping it, waiting for 1 second, rinse, repeat), deadlock can occur within minutes of running. But, repeating myself, this occurs sooner or later regardless of all these parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants