Skip to content

Add flag to only stop device scan if it as started at least once before - #37

Open
ebariaux wants to merge 2 commits into
mainfrom
bugfix/espprovision-stop-scan
Open

Add flag to only stop device scan if it as started at least once before#37
ebariaux wants to merge 2 commits into
mainfrom
bugfix/espprovision-stop-scan

Conversation

@ebariaux

@ebariaux ebariaux commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@ebariaux ebariaux added the Bug Error or issue in the system label Aug 4, 2026
@ebariaux
ebariaux requested a review from a team August 4, 2026 14:08
@denniskuijs
denniskuijs requested review from a team and a lite review from Copilot August 4, 2026 14:12

@MartinaeyNL MartinaeyNL left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this work? Won't searchedAtLeastOnce be incorrect after a 2nd device provisioning?

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 pull request adds state to the ESP provisioning wrapper so stopESPDevicesSearch() is only invoked after at least one device search has been started, aiming to avoid a known crash in the underlying ESPProvision library.

Changes:

  • Convert EspressifProvisionManager from a struct to a class to retain state across calls.
  • Track whether a search has ever been started and guard stopESPDevicesSearch() accordingly.
  • Add an initializer to support injecting an ESPProvisionManager instance.
Suppressed comments (3)

ORLib/ConsoleProviders/ESPProvision/DeviceRegistry.swift:45

  • This assignment should be updated to match the renamed/encapsulated flag (e.g., hasSearchedAtLeastOnce) so it stays consistent with the guard in stopESPDevicesSearch().
            searchedAtLeastOnce = true

ORLib/ConsoleProviders/ESPProvision/DeviceRegistry.swift:63

  • Guarding stopESPDevicesSearch() with a local "has searched" flag avoids the known crash, but it can also make stopDevicesScan() a no-op if it’s called before the async scan task reaches searchESPDevices() (the task will still start a search later). Consider preventing searches from starting after bleScanning is set to false (e.g., check bleScanning before initiating searchESPDevices in DeviceRegistry.devicesScan) and/or introducing an explicit cancellable scan task instead of relying on this flag alone.
        // ESPProvisionManager.stopESPDevicesSearch crashes by force unwrapping nil if it did not perform a search before
        guard searchedAtLeastOnce else { return }
        provisionManager.stopESPDevicesSearch()

ORLib/ConsoleProviders/ESPProvision/DeviceRegistry.swift:62

  • Update the guard to match the renamed flag so the code compiles and the intent stays clear.
        guard searchedAtLeastOnce else { return }

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

Comment thread ORLib/ConsoleProviders/ESPProvision/DeviceRegistry.swift Outdated
@ebariaux

ebariaux commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@MartinaeyNL Issue is with Espressif code, some object is nil if not initialised by a search, but when done once that object stays around forever

@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Error or issue in the system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESPProvisionManager crash: stopESPDevicesSearch() unexpected found nil

3 participants