Skip to content

3324 - Resolve deadlocking on async operations - #3328

Open
ColinM9991 wants to merge 2 commits into
MobiFlight:mainfrom
ColinM9991:3324/thread-synchronization-deadlock
Open

3324 - Resolve deadlocking on async operations#3328
ColinM9991 wants to merge 2 commits into
MobiFlight:mainfrom
ColinM9991:3324/thread-synchronization-deadlock

Conversation

@ColinM9991

@ColinM9991 ColinM9991 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

This resolves a deadlocking issue in JoystickManager where Task.Run is used without scheduling the operation to continue on a background thread. The UI thread is busy doing other workso the application hangs until it is able to continue again. This manifested itself on lower end hardware, though that isn't conclusive yet.

Many other files have been updated to append ConfigureAwait(false) where a task is awaited.

Related issues

fixes #3324

Out-of-scope

@github-actions

Copy link
Copy Markdown

Build for this pull request:
MobiFlightConnector.zip

@ColinM9991
ColinM9991 marked this pull request as ready for review August 31, 2026 17:33
@ColinM9991
ColinM9991 requested a review from DocMoebiuz as a code owner August 31, 2026 17:33
@DocMoebiuz
DocMoebiuz requested a lite review from Copilot September 1, 2026 12:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Addresses reported startup hangs/deadlocks (#3324) by adjusting async continuations—primarily adding ConfigureAwait(false) to avoid resuming on the UI synchronization context—across several background/IO paths (device enumeration, delays, update checking, firmware update flow).

Changes:

  • Added ConfigureAwait(false) to multiple awaited operations (Task.Run, Task.Delay, Task.WhenAny) to reduce UI-thread continuation pressure.
  • Updated joystick enumeration to run asynchronously rather than blocking the UI path.
  • Extended similar continuation behavior to related background components (USB monitor, WASM updater retry delay, script runner polling).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/MobiFlightUnitTests/mock/MobiFlight/MobiFlightCacheMock.cs Adds ConfigureAwait(false) to async mock module retrieval.
src/MobiFlightConnector/UI/Forms/FirmwareUpdateProcess.cs Applies ConfigureAwait(false) to firmware timeout WhenAny await.
src/MobiFlightConnector/SimConnectMSFS/WasmModuleUpdater.cs Adds ConfigureAwait(false) to retry delay.
src/MobiFlightConnector/MobiFlight/Scripts/ScriptRunner.cs Adds ConfigureAwait(false) to startup/polling delays.
src/MobiFlightConnector/MobiFlight/Monitors/UsbDeviceMonitor.cs Adds ConfigureAwait(false) to readiness timeout WhenAny await.
src/MobiFlightConnector/MobiFlight/Monitors/DeviceMonitor.cs Adds ConfigureAwait(false) to delayed scan kickoff chain.
src/MobiFlightConnector/MobiFlight/MobiFlightCache.cs Uses ConfigureAwait(false) around background module connection detection and delayed lookup completion.
src/MobiFlightConnector/MobiFlight/Joysticks/JoystickManager.cs Adds ConfigureAwait(false) after background device enumeration.
src/MobiFlightConnector/Base/AutoUpdateChecker.cs Adds ConfigureAwait(false) after installer check execution.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/MobiFlightConnector/UI/Forms/FirmwareUpdateProcess.cs Outdated
try
{
(output, error) = await Task.Run(() => RunInstallerCheck(CommandToSend));
(output, error) = await Task.Run(() => RunInstallerCheck(CommandToSend)).ConfigureAwait(false);

// Currently thread change necessary, otherwise exception in board reset process.
await Task.Delay(50).ContinueWith(_ => Scan());
await Task.Delay(50).ContinueWith(_ => Scan()).ConfigureAwait(false);
Comment on lines +198 to +199
var devices = await Task.Run(() => di.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly).ToList())
.ConfigureAwait(false);
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Build for this pull request:
MobiFlightConnector.zip

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

Successfully merging this pull request may close these issues.

MobiFlight hangs during startup

2 participants