Skip to content

Harden COM port enumeration to avoid Bluetooth-driven startup/dropdown crashes - #3740

Open
meee1 with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-mission-planner-crash-bluetooth-com-ports
Open

Harden COM port enumeration to avoid Bluetooth-driven startup/dropdown crashes#3740
meee1 with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-mission-planner-crash-bluetooth-com-ports

Conversation

Copilot AI commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

On some Windows 10 systems, opening or initializing the COM port selector could crash Mission Planner when Bluetooth serial drivers stall or misbehave during port enumeration. This change makes COM discovery resilient so the UI remains responsive and usable even when a driver hangs or throws.

  • Serial enumeration timeout + fallback

    • MissionPlanner.Comms.SerialPort.GetPortNames() no longer depends solely on System.IO.Ports.SerialPort.GetPortNames().
    • Added timeout-protected system enumeration path.
    • On timeout/failure (Windows), falls back to registry-backed COM discovery via HARDWARE\DEVICEMAP\SERIALCOMM.
  • UI crash containment in port dropdown population

    • Wrapped PopulateSerialportList() COM port insertion path in guarded error handling.
    • Dropdown still populates baseline connection options even if COM discovery faults.
  • Diagnostics improvements

    • Replaced generic exception logging with contextual messages for:
      • system port enumeration failures/timeouts
      • Windows registry COM fallback failures
      • serial dropdown population failures
private static string[] GetSystemPortNames()
{
    var ports = GetSystemPortNamesWithTimeout(SystemPortEnumerationTimeoutMs);
    if (ports != null) return ports;

    if (Environment.OSVersion.Platform == PlatformID.Win32NT)
        return GetWindowsRegistryPortNames();

    return Array.Empty<string>();
}

Copilot AI changed the title [WIP] Fix crash in Mission Planner when scanning Bluetooth COM ports Harden COM port enumeration to avoid Bluetooth-driven startup/dropdown crashes Jun 12, 2026
Copilot finished work on behalf of meee1 June 12, 2026 21:41
Copilot AI requested a review from meee1 June 12, 2026 21:41
@meee1
meee1 requested a review from Copilot July 2, 2026 06:29
@meee1
meee1 marked this pull request as ready for review July 2, 2026 06:29
@meee1
meee1 force-pushed the copilot/fix-mission-planner-crash-bluetooth-com-ports branch from 23f48cb to e9cb1ae Compare July 2, 2026 06:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent Mission Planner startup/UI crashes and hangs caused by problematic serial/Bluetooth drivers during COM port enumeration by adding a timeout-protected enumeration path with a Windows registry fallback, plus additional guarding when populating the serial-port dropdown.

Changes:

  • Added a timeout-based COM port enumeration path with Windows registry fallback (HARDWARE\DEVICEMAP\SERIALCOMM) in MissionPlanner.Comms.SerialPort.GetPortNames().
  • Wrapped serial-port dropdown population in MainV2.PopulateSerialportList() with exception handling to keep the UI responsive.
  • Updated logging to include more contextual error messages (but some new messages currently don’t match the code paths they’re in).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
MainV2.cs Adds guarded COM port dropdown population and updates error logging around connection/setup paths.
ExtLibs/Comms/CommsSerialPort.cs Introduces timeout-based system COM enumeration with Windows registry fallback for resilience.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread MainV2.cs
catch (Exception ex)
{
log.Error(ex);
log.Error("Failed to enumerate serial ports for connection list.", ex);
Comment thread MainV2.cs
catch (Exception ex)
{
log.Error(ex);
log.Error("Failed to populate serial port dropdown.", ex);
Comment on lines +327 to +347
private static string[] GetSystemPortNamesWithTimeout(int timeoutMilliseconds)
{
string[] ports = null;

try
{
CallWithTimeout(_ => { ports = System.IO.Ports.SerialPort.GetPortNames(); }, timeoutMilliseconds, 0);
}
catch (TimeoutException ex)
{
log.Warn($"System.IO.Ports.SerialPort.GetPortNames timed out after {timeoutMilliseconds} ms.", ex);
return null;
}
catch (Exception ex)
{
log.Error("Unexpected error while enumerating system serial ports.", ex);
return null;
}

return ports ?? Array.Empty<string>();
}
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.

3 participants