Skip to main content

Function: performPingCheckWithRetry()

function performPingCheckWithRetry(
host: string,
timeout: number,
maxRetries: number,
signal?: AbortSignal
): Promise<MonitorCheckResult>;

Defined in: electron/services/monitoring/utils/pingRetry.ts:223

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)

signal?​

AbortSignal

Returns​

Promise<MonitorCheckResult>

Promise resolving to MonitorCheckResult with connectivity status, timing, and details

Remarks​

This function wraps the internal single-attempt connectivity check 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:

  1. Validates input parameters
  2. Performs initial connectivity attempt
  3. On failure, retries with exponential backoff
  4. 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​