Skip to content

[Bug] networkMonitor emits connectionRestored before new requests can succeed — race condition #634

Description

@RUKAYAT-CODER

Overview

src/services/networkMonitor.ts emits 'connectionRestored' event immediately when NetInfo reports isConnected: true. Subscribers (including requestQueue) immediately start replaying queued requests. However, the network stack may take 1-3 seconds after the isConnected event before DNS resolution and TCP connections succeed. The first replayed requests fail, are re-queued, and the retry logic starts from scratch.

Specifications

Features:

  • After isConnected becomes true, perform a lightweight connectivity probe before emitting connectionRestored
  • Probe: single HEAD request to /api/health with 5-second timeout
  • If probe succeeds: emit connectionRestored
  • If probe fails: wait 2 seconds and retry probe (max 5 probes before giving up)
  • Total delay: typically < 2 seconds, max 12 seconds before declaring restored

Tasks:

  • Add probeConnectivity(): Promise<boolean> in networkMonitor.ts
  • Modify NetInfo isConnected handler to call probe before event emit
  • Expose isProbingConnectivity state for UI indicators
  • Add unit tests for probe success, failure, and timeout scenarios

Impacted Files:

  • src/services/networkMonitor.ts

Acceptance Criteria

  • connectionRestored event fires only after successful connectivity probe
  • Queue replay does not trigger until connectionRestored fires
  • Probe timeout is 5 seconds maximum
  • Unit test confirms event not emitted on probe failure

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't working

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