Skip to content

Guard the default netifs against being created twice - #3526

Open
dkovyazin wants to merge 2 commits into
nanoframework:mainfrom
ledtrees:prep/netif-guards
Open

Guard the default netifs against being created twice#3526
dkovyazin wants to merge 2 commits into
nanoframework:mainfrom
ledtrees:prep/netif-guards

Conversation

@dkovyazin

Copy link
Copy Markdown
Contributor

Description

  • The default STA and AP netifs are only created when the stored pointer is still NULL.

Motivation and Context

IsWifiInitialised is set at the very end of NF_ESP32_InitaliseWifi(), while several return statements sit between the netif creation and that assignment - a failing esp_wifi_init(), esp_wifi_set_mode(), esp_wifi_start() or the AP configuration block. After such a failure the netifs exist but the module still considers itself uninitialised, so the next call re-enters the same branch and creates a second default netif for the same interface. The first one is leaked and esp_netif refuses to attach the second.

NF_ESP32_DeinitWifi() already sets both pointers back to NULL, so a clean de-init followed by an init still creates them.

How Has This Been Tested?

  • Built for an ESP32-S3 target against current main.
  • Exercised on hardware where a Wi-Fi initialisation failure is followed by a retry, which previously left a leaked netif behind.

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

IsWifiInitialised is set at the very end of NF_ESP32_InitaliseWifi(), while
several returns sit between the netif creation and that assignment - a failing
esp_wifi_init(), esp_wifi_set_mode(), esp_wifi_start() or the AP configuration
block. After such a failure the netifs exist but the module still considers
itself uninitialised, so the next call re-enters the same branch and creates a
second default netif for the same interface: the first one is leaked and
esp_netif refuses to attach the second.

Create them only when the stored pointer is still NULL. NF_ESP32_DeinitWifi()
sets both back to NULL, so a clean de-init followed by an init still creates
them.
@nfbot nfbot added the Type: bug label Sep 6, 2026
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Team

Run ID: f74d3ee7-b823-4de4-9d8b-8bbfabf76198

📥 Commits

Reviewing files that changed from the base of the PR and between f37471b and f5c7aa4.

📒 Files selected for processing (1)
  • targets/ESP32/_Network/NF_ESP32_Wireless.cpp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@josesimoes josesimoes 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.

The fix looks OK. Just remove the verbose comment. THe reasoning is perfectly explained in the PR comments where it belongs.

@josesimoes josesimoes added the Platform: ESP32 Everything related specifically with ESP32 platform label Sep 7, 2026
@dkovyazin

Copy link
Copy Markdown
Contributor Author

Comments removed in f5c7aa4 — the reasoning stays in the PR description.

@josesimoes

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@josesimoes

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

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

Labels

Platform: ESP32 Everything related specifically with ESP32 platform Type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESP32: a failed Wi-Fi init leaks the default netif and breaks the retry

3 participants