Skip to content

Conversation

@mattt
Copy link
Collaborator

@mattt mattt commented Sep 24, 2025

Follow-up to #229

@pcuenca observed that tests were failing locally because shouldUseOfflineMode was occasionally evaluating isConnected to be false. This new behavior occurred after switching to Swift Testing, in #229. That PR didn't change anything about offline mode, but it did increase test parallelism, which I suspect surfaced a race condition in the network monitor.

This PR updates the network monitor to seed the offline / online state immediately from NWPathMonitor.currentPath after calling startMonitoring. This should fix intermittent offline-mode activation that's observed running tests locally.

@mattt

This comment was marked as resolved.

@mattt mattt force-pushed the mattt/fix-network-monitor-race branch from 091d6c8 to 78d3173 Compare September 25, 2025 12:23
Task {
await self.state.update(path: path)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Noticed that startMonitoring gets called twice using the singleton method NetworkMonitor.shared.startMonitoring() if one doesnt yet exist. May want to also add a check for monitor.pathUpdateHandler == nil before setting it here in case the first update goes to a handler that was already replaced.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants