Skip to main content

Function: performSinglePortCheck()

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

Defined in: electron/services/monitoring/utils/portChecker.ts:93

Performs a single TCP port connectivity check to a specified host and port, without retry logic.

Parameters​

host​

string

The target hostname or IP address to check (e.g., "localhost", "192.168.1.1").

port​

number

The TCP port number to test for connectivity.

timeout​

number

The maximum time to wait for a connection, in milliseconds.

signal?​

AbortSignal

Returns​

Promise<MonitorCheckResult>

A promise that resolves to a MonitorCheckResult containing port details, response time, and status.

Remarks​

Uses the is-port-reachable library to test TCP connectivity to the given host and port, measuring response time with high-precision performance.now(). Debug logging is enabled in development mode. This function does not mutate state or trigger events; it is intended for use within repository or service layers that handle orchestration and event propagation.

On success, resolves to a MonitorCheckResult with status "up" and the measured response time. On failure, throws a PortCheckError containing the error message and response time for use in retry or error handling logic.

Example​

import { monitorLogger } from "../../../utils/logger";

try {
const result = await performSinglePortCheck("example.com", 80, 5000);
monitorLogger.info("Port check result", result);
} catch (error) {
if (error instanceof PortCheckError) {
monitorLogger.warn("Port unreachable", {
responseTime: error.responseTime,
});
}
}

Throws​

  • Thrown if the port is not reachable within the timeout, with response time included for diagnostics and retry logic.

Throws​

  • When port check fails

See​