Skip to content

Commit

Permalink
fix NodeJS.Timeout issue caused by latest @types/node ts definition r…
Browse files Browse the repository at this point in the history
…efinement
  • Loading branch information
erossignon committed Aug 15, 2023
1 parent 8b3716d commit 6367995
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 20 deletions.
Expand Up @@ -49,7 +49,7 @@ export const TwoWeeksDuration = OneDayDuration * 2 * 7;
* of expiration. This alarm automatically returns to normal when the certificate is updated.
*/
class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implements UACertificateExpirationAlarmEx {
private timer: any;
private timer: NodeJS.Timeout | null = null;

public static instantiate(
namespace: INamespace,
Expand Down
Expand Up @@ -26,14 +26,14 @@ const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);

export interface UAShelvedStateMachineHelper {
_timer: NodeJS.Timer | null;
_timer: NodeJS.Timeout | null;
_sheveldTime: Date;
_unshelvedTime: Date;
_duration: number;
}

export interface UAShelvedStateMachineExImpl extends UAShelvedStateMachineHelper {
unshelveTime: UAProperty<number, /*z*/ DataType.Double>;
unshelveTime: UAProperty<number, /*z*/ DataType.Double>;
unshelved: UAState;
timedShelved: UAState;
oneShotShelved: UAState;
Expand Down
Expand Up @@ -11,7 +11,6 @@ import { AttributeIds } from "node-opcua-basic-types";
import { checkDebugFlag, make_debugLog, make_warningLog } from "node-opcua-debug";
import { coerceNodeId } from "node-opcua-nodeid";
import { ClientSecureChannelLayer } from "node-opcua-secure-channel";
import { StatusCodes } from "node-opcua-status-code";
import { ClientSessionImpl } from "./private/client_session_impl";

const serverStatusStateNodeId = coerceNodeId(VariableIds.Server_ServerStatus_State);
Expand All @@ -27,7 +26,7 @@ export interface ClientSessionKeepAliveManagerEvents {

export class ClientSessionKeepAliveManager extends EventEmitter implements ClientSessionKeepAliveManagerEvents {
private readonly session: ClientSessionImpl;
private timerId?: NodeJS.Timer;
private timerId?: NodeJS.Timeout;
private pingTimeout: number;
private lastKnownState?: ServerState;
private transactionInProgress = false;
Expand Down
Expand Up @@ -307,7 +307,7 @@ function _adjustRevisedSessionTimeout(revisedSessionTimeout: number, requestedTi
*/
export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
public static minimumRevisedSessionTimeout = 100.0;
private _retryCreateSessionTimer?: NodeJS.Timer;
private _retryCreateSessionTimer?: NodeJS.Timeout;

public static create(options: OPCUAClientOptions): OPCUAClient {
return new OPCUAClientImpl(options);
Expand Down
10 changes: 9 additions & 1 deletion packages/node-opcua-client/source/verify.ts
Expand Up @@ -8,6 +8,7 @@ import {
publicKeyAndPrivateKeyMatches
} from "node-opcua-crypto";
import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
import { VerifyCertificateOptions } from "node-opcua-pki";

const doDebug = checkDebugFlag(__filename);
const debugLog = make_debugLog(__filename);
Expand Down Expand Up @@ -150,7 +151,14 @@ export async function performCertificateSanityCheck(
}
// verify that the certificate has a valid date and has expected extensions fields such as DNS and IP.
const status1 = await certificateManager.trustCertificate(certificate);
const status = await certificateManager.verifyCertificateAsync(certificate);

const options: VerifyCertificateOptions = {
acceptOutdatedCertificate: false,
acceptOutDatedIssuerCertificate: false,
acceptPendingCertificate: false,
};

const status = await certificateManager.verifyCertificate(certificate, options);

if (status !== "Good") {
warningLog("[NODE-OPCUA-W04] Warning: the certificate status is = ", status, " file = ", secureObject.certificateFile);
Expand Down
Expand Up @@ -264,7 +264,7 @@ describe("KJH2 testing ability for client to reconnect when server close connect
let temperatureVariableId: NodeId;

let counterNode: UAVariable;
let timerId: NodeJS.Timer | undefined = undefined;
let timerId: NodeJS.Timeout | undefined = undefined;
// -----------------------------------------------------------------------------------------------------------------
// Common Steps
// -----------------------------------------------------------------------------------------------------------------
Expand Down
Expand Up @@ -19,7 +19,7 @@ import should from "should";

const _should = should;

let timer1: any;
let timer1: NodeJS.Timeout | undefined;
let _variableNode2: UAVariable;
let _variableNode1: UAVariable;

Expand Down
Expand Up @@ -362,7 +362,7 @@ export class ClientSecureChannelLayer extends EventEmitter {

private __in_normal_close_operation: boolean;
private _timeout_request_count: number;
private _securityTokenTimeoutId: NodeJS.Timer | null;
private _securityTokenTimeoutId: NodeJS.Timeout | null;
private readonly transportTimeout: number;
private readonly connectionStrategy: any;
private last_transaction_stats: any | ClientTransactionStatistics;
Expand Down
Expand Up @@ -283,9 +283,9 @@ export class ServerSecureChannelLayer extends EventEmitter {
private receiverPublicKeyLength: number;
private readonly messageChunker: MessageChunker;

private timeoutId: NodeJS.Timer | null;
private timeoutId: NodeJS.Timeout | null;
private _open_secure_channel_onceClose: ErrorCallback | null = null;
private _securityTokenTimeout: NodeJS.Timer | null;
private _securityTokenTimeout: NodeJS.Timeout | null;
private _transactionsCount: number;
private revisedLifetime: number;
private readonly transport: ServerTCP_transport;
Expand Down
4 changes: 2 additions & 2 deletions packages/node-opcua-server/source/monitored_item.ts
Expand Up @@ -398,7 +398,7 @@ export class MonitoredItem extends EventEmitter {
public queueSize = 0;
public clientHandle: UInt32;
public $subscription?: ISubscription;
public _samplingId?: TimerKey | string;
public _samplingId?: NodeJS.Timeout | string;
public samplingFunc: SamplingFunc | null = null;

private _node: BaseNode | null;
Expand Down Expand Up @@ -1331,7 +1331,7 @@ export class MonitoredItem extends EventEmitter {
if (useCommonTimer) {
removeFromTimer(this);
} else {
clearInterval(this._samplingId as NodeJS.Timer);
clearInterval(this._samplingId);
}
this._samplingId = undefined;
}
Expand Down
11 changes: 9 additions & 2 deletions packages/node-opcua-server/source/node_sampler.ts
Expand Up @@ -11,7 +11,12 @@ const doDebug = checkDebugFlag(__filename);

import { MonitoredItem } from "./monitored_item";

const timers: any = {};
interface ITimer {
_samplingId: NodeJS.Timeout | false,
monitoredItems: Record<string,any>,
monitoredItemsCount: number;
}
const timers: Record<string,ITimer> = {};
const NS_PER_SEC = 1e9;

interface MonitoredItemPriv {
Expand Down Expand Up @@ -85,7 +90,9 @@ export function removeFromTimer(monitoredItem: MonitoredItem): void {
_t.monitoredItemsCount--;
assert(_t.monitoredItemsCount >= 0);
if (_t.monitoredItemsCount === 0) {
clearInterval(_t._samplingId);
if (_t._samplingId !==false) {
clearInterval(_t._samplingId);
}
delete timers[key];
}
}
Expand Up @@ -298,7 +298,7 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
public timeout: number;

private server: IPartialServer | null;
private _registrationTimerId: NodeJS.Timer | null;
private _registrationTimerId: NodeJS.Timeout | null;
private state: RegisterServerManagerStatus = RegisterServerManagerStatus.INACTIVE;
private _registration_client: OPCUAClientBase | null = null;
private selectedEndpoint?: EndpointDescription;
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-transport/source/tcp_transport.ts
Expand Up @@ -163,7 +163,7 @@ export class TCP_transport extends EventEmitter {
* @default 8
*/
private readonly headerSize: 8;
private _timerId: NodeJS.Timer | null;
private _timerId: NodeJS.Timeout | null;
private _theCallback?: (err?: Error | null, data?: Buffer) => void;
private _on_error_during_one_time_message_receiver: ((hadError: boolean) => void) | undefined;
private packetAssembler?: PacketAssembler;
Expand Down
4 changes: 2 additions & 2 deletions packages/node-opcua-utils/source/watchdog.ts
Expand Up @@ -62,7 +62,7 @@ export class WatchDog extends EventEmitter {
private readonly _watchdogDataMap: { [id: number]: IWatchdogData2 };
private _counter: number;
private _currentTime: ArbitraryClockTick;
private _timer: NodeJS.Timer | null;
private _timer: NodeJS.Timeout | null;
private readonly _visitSubscriberB: (...args: any[]) => void;

constructor() {
Expand Down Expand Up @@ -140,7 +140,7 @@ export class WatchDog extends EventEmitter {

delete this._watchdogDataMap[subscriber._watchDogData.key];
delete subscriber._watchDog;
// leave it as it might be usefull, delete subscriber._watchDogData;
// leave it as it might be useful, delete subscriber._watchDogData;
subscriber.keepAlive = WatchDog.emptyKeepAlive;

// delete timer when the last subscriber comes out
Expand Down

0 comments on commit 6367995

Please sign in to comment.