Skip to content

fix(wlan): addCredentials/clearCredentials NVS write from async_tcp context #241

@Phantomias2006

Description

@Phantomias2006

Problem

addCredentials(force=true) and clearCredentials() call saveConfig() directly from async_tcp body handlers (addNetwork at WebHandler.cpp:732, handleClearWifi at WebHandler.cpp:365). Settings::write() opens Preferences, serializes JSON, and writes to NVS — blocking the calling task for typically 30–200 ms, up to 500+ ms during flash sector garbage collection.

Root Cause

The B39 fix introduced wlanSaveConfigPending (already used in update() at Wlan.cpp:258–262) but the pattern was not applied to addCredentials (force path) and clearCredentials. Both still call saveConfig() synchronously from the async_tcp task.

Fix

Replace direct saveConfig() calls with wlanSaveConfigPending = true in both functions. The flag is already processed in Wlan::update() (ConnectTask context), which is the correct async-safe execution path — identical to the B39 fix pattern.

Review-Finding: CR-003-001
Severity: CRITICAL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions