Data syncs correctly when reconnected after offline period
Why it matters
An app that does not automatically sync on reconnect forces users to manually pull-to-refresh or restart the app to see changes made on another device or from the server. CWE-362 applies when the window between going offline and reconnecting allows remote state to diverge without the client knowing. ISO 25010:2011 reliability.recoverability requires that the app reaches a consistent state after a connectivity gap without user intervention. In collaborative or multi-device scenarios, the failure to auto-sync on reconnect means users work on stale data, potentially overwriting remote changes.
Severity rationale
High because missing auto-sync on reconnect leaves local and remote state silently diverged, which can cause data overwrites or user confusion in multi-device scenarios.
Remediation
Detect the offline→online transition in your NetInfo listener and trigger a full sync cycle — upload queued local changes first, then fetch remote updates, then reconcile.
import { useEffect, useRef, useState } from 'react';
import NetInfo from '@react-native-community/netinfo';
export function useSyncOnReconnect() {
const [isOnline, setIsOnline] = useState(true);
const wasOnline = useRef(true);
useEffect(() => {
const unsub = NetInfo.addEventListener(async (state) => {
const online = state.isConnected ?? false;
if (!wasOnline.current && online) {
// Transition: offline → online
await drainQueue(executeAction); // flush local writes
await fetchRemoteUpdates(); // pull server state
await reconcileConflicts(); // merge (see conflict-resolution-strategy)
}
wasOnline.current = online;
setIsOnline(online);
});
return unsub;
}, []);
return isOnline;
}
Run this hook at root navigator level so the sync fires regardless of which screen the user is on when connectivity returns.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Mobile Offline & Storage Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-362 — Concurrent Execution Using Shared Resource with Improper Synchronization (Race Condition)
- iso-25010:2011 · reliability.recoverability — Recoverability
Taxons
History
- 2026-04-18·v1.0.0·Initial import from mobile-offline-storage·automated