Skip to content

feat: Add Auto Master status check in PnP flow to prevent race condition #980

Description

@AustinChangLinksys

Related Issue

Background

After factory reset, if WAN is connected to the internet, the Router will automatically trigger the Auto Master flow. If the user opens PnP while Auto Master is in progress, SetDeviceMode will fail (returning ErrorAlreadyMaster), causing the entire PnP transaction to abort.

This occurs because both Auto Master and PnP attempt to set the Router to Master mode, creating a race condition.

Solution

FW team provides a new JNAP action for the App to query Auto Master status:

  • Action: http://linksys.com/jnap/nodes/setup/GetAutoMasterStatus
  • Response: { "autoMasterStatus": "Idle" | "Running" | "Complete" }

Implement two defense lines:

Defense Location Timing Handling
First PnP Admin After examineAdminPassword If Running → show waiting UI → redirect to login page after completion
Second PnP Setup Before save If Running → show waiting UI → redirect to login page; If was Idle on entry but now Complete → redirect to login page

Scenario Analysis

Auto Master Status Password State Handling
Complete WiFi password changed examineAdminPassword requires password input, normal PnP flow
Running admin (default) Show waiting UI → poll → redirect to login page after completion
Idle admin (default) Normal PnP flow
Edge Case: Idle → Complete Password changed Second defense detects before save, redirect to login page

Edge Cases

1. Idle → Complete (Core scenario for second defense)

  • Auto Master status is Idle when entering PnP Config
  • During configuration, network suddenly recovers and triggers Auto Master which completes
  • Password has changed from default admin to WiFi password
  • Second defense detects status changed from Idle to Complete before save, redirects to login page

2. Network recovery during Troubleshooting flow

  • User enters troubleshooting page due to no internet
  • Network recovers after ISP settings or modem restart
  • Network recovery may trigger Auto Master
  • Handling:
    • Try Again / ISP settings success / Modem restart → back to pnp → goes through first defense ✅
    • Log into Router → directly to pnpConfig → goes through second defense ✅

3. Router restart during Auto Master

  • Router restarts when Auto Master executes SetMaster
  • WiFi disconnects during restart, phone may auto-connect to other networks
  • JNAP polling will fail consecutively (timeout)
  • Handling: After 3 consecutive failures, show connection error UI prompting user to verify WiFi connection with Retry button

4. Legacy FW without GetAutoMasterStatus support

  • checkAutoMasterStatus() returns null on failure
  • Treated as Idle, continues normal PnP flow (backward compatible)

Connection Error Handling

During Auto Master, the Router will restart due to SetMaster, which may cause WiFi disconnection (phone auto-connects to other networks).

Handling:

  • When polling fails 3 consecutive times (timeout/error), show connection error UI
  • Prompt: "Router Not Found - Please make sure your device is connected to the correct WiFi network"
  • Provide Retry button for user to retry

Implementation Files

File Description
lib/core/jnap/models/auto_master_status.dart New - AutoMasterStatus enum and response model
lib/core/jnap/actions/jnap_action.dart Add getAutoMasterStatus enum
lib/core/jnap/actions/jnap_action_value.dart Add URL mapping
lib/core/jnap/actions/better_action.dart Register action
lib/page/instant_setup/data/pnp_provider.dart Add checkAutoMasterStatus / pollAutoMasterStatus / setAutoMasterStatusOnEntry
lib/page/instant_setup/data/pnp_state.dart Add autoMasterStatusOnEntry field
lib/page/instant_setup/widgets/pnp_auto_master_waiting_view.dart New - waiting UI + connection error UI
lib/page/instant_setup/pnp_admin_view.dart First defense implementation
lib/page/instant_setup/pnp_setup_view.dart Second defense implementation

Testing

  • Added screenshot tests to verify waiting UI and connection error UI

Metadata

Metadata

Labels

1.xLabeled for 1.x versionconfidence:lowInsufficient evidence; body-only speculation (not posted)

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions