Function: performPingCheckWithRetry()
performPingCheckWithRetry(
host:string,timeout:number,maxRetries:number):Promise<MonitorCheckResult>
Defined in: electron/services/monitoring/utils/pingRetry.ts:166
Performs a connectivity check with retry logic and exponential backoff.
Parameters
host
string
Target hostname, IP address, or URL to check connectivity for
timeout
number
Maximum time to wait for each connectivity attempt in milliseconds
maxRetries
number
Number of additional retry attempts after initial failure (0 = try once only)
Returns
Promise resolving to MonitorCheckResult with connectivity status, timing, and details
Remarks
This function wraps performSinglePingCheck with retry logic using
withOperationalHooks. It attempts to check connectivity to the
specified host, retrying on failure up to maxRetries times (for a total of
maxRetries + 1 attempts). Exponential backoff is applied between
attempts.
Process flow:
- Validates input parameters
- Performs initial connectivity attempt
- On failure, retries with exponential backoff
- Returns standardized result or error
Debug logging is enabled in development mode to aid troubleshooting. If all attempts fail, returns a standardized error result via handlePingCheckError.
Example
import { monitorLogger } from "../../../utils/logger";
// Try once, no retries
const result = await performPingCheckWithRetry("example.com", 5000, 0);
// Try 4 times total (1 initial + 3 retries) with 3-second timeout
const result = await performPingCheckWithRetry("google.com", 3000, 3);
if (result.status === "up") {
monitorLogger.info("Connectivity successful", result);
} else {
monitorLogger.warn("Connectivity failed", {
error: result.error,
});
}
See
- withOperationalHooks - Retry logic implementation
- performSinglePingCheck - Single connectivity attempt function
- handlePingCheckError - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Error handling utility