Skip to content

Commit

Permalink
contexts isActive error on null
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq committed Feb 7, 2025
1 parent 5aa815c commit 5738ab8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions common/lib/plugins/efm2/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ export class MonitorImpl implements Monitor {

let monitorContextRef: WeakRef<MonitorConnectionContext> | undefined;

while ((monitorContextRef = this.activeContexts.shift()) != null) {
while ((monitorContextRef = this.activeContexts.shift())) {
if (this.isStopped()) {
break;
}
const monitorContext = monitorContextRef.deref();
if (monitorContext == null) {
const monitorContext: MonitorConnectionContext = monitorContextRef?.deref() ?? null;
if (!monitorContext) {
continue;
}

Expand All @@ -193,15 +193,15 @@ export class MonitorImpl implements Monitor {
await this.endMonitoringClient();
this.abortedConnectionsCounter.inc();
}
} else if (monitorContext.isActive()) {
} else if (monitorContext && monitorContext.isActive()) {
tmpActiveContexts.push(monitorContextRef);
}

// activeContexts is empty now and tmpActiveContexts contains all yet active contexts
// Add active contexts back to the queue.
this.activeContexts.push(...tmpActiveContexts);

const delayMillis = this.failureDetectionIntervalNanos - (statusCheckEndTimeNanos - statusCheckStartTimeNanos) / 1000000;
const delayMillis = (this.failureDetectionIntervalNanos - (statusCheckEndTimeNanos - statusCheckStartTimeNanos)) / 1000000;

await new Promise((resolve) => {
this.delayMillisTimeoutId = setTimeout(
Expand All @@ -211,11 +211,11 @@ export class MonitorImpl implements Monitor {
});
}
} catch (error: any) {
logger.debug(Messages.get("MonitorImpl.exceptionDuringMonitoringContinue", error.message));
logger.debug(Messages.get("MonitorImpl.errorDuringMonitoringContinue", error.message));
}
}
} catch (error: any) {
logger.debug(Messages.get("MonitorImpl.exceptionDuringMonitoringStop", error.message));
logger.debug(Messages.get("MonitorImpl.errorDuringMonitoringStop", error.message));
} finally {
await this.endMonitoringClient();
await sleep(3000);
Expand Down Expand Up @@ -245,7 +245,7 @@ export class MonitorImpl implements Monitor {
}

logger.debug(`Opening a monitoring connection to ${this.hostInfo.url}`);
this.monitoringClient = await this.pluginService.forceConnect(this.hostInfo, this.properties);
this.monitoringClient = await this.pluginService.forceConnect(this.hostInfo, monitoringConnProperties);
logger.debug(`Successfully opened monitoring connection to ${this.monitoringClient.id} - ${this.hostInfo.url}`);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion common/lib/plugins/efm2/monitor_connection_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class MonitorConnectionContext {
}

isActive() {
return this.clientToAbortRef.deref() !== null;
const val = this.clientToAbortRef?.deref() ?? null;
return val !== null;
}
}
3 changes: 1 addition & 2 deletions common/lib/utils/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,5 @@
"HostMonitor.detectedWriter": "Detected writer: '%s'.",
"HostMonitor.endMonitoring": "Host monitor '%s' completed in '%s'.",
"HostMonitor.writerHostChanged": "Writer host has changed from '%s' to '%s'.",
"HostMonitoringConnectionPlugin.monitoringDeactivated": "Monitoring deactivated for method '%s'.",
"MonitorImpl.exceptionDuringMonitoringContinue": "MonitorImpl.exceptionDuringMonitoringContinue"
"HostMonitoringConnectionPlugin.monitoringDeactivated": "Monitoring deactivated for method '%s'."
}

0 comments on commit 5738ab8

Please sign in to comment.