mirror of https://git.tuxpa.in/a/code-server.git
Fix port scanner when netstat isn't available
- It logs the error now. - For some reason when there is an error node-netstat runs the callback twice. That resulted in us scheduling an exponentially growing number of calls which ate up all the CPU (and probably memory eventually). For now, opted to dispose when there is an error.
This commit is contained in:
parent
cdc40d36ff
commit
d16c6aeb30
|
@ -1,6 +1,7 @@
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
import * as netstat from "node-netstat";
|
import * as netstat from "node-netstat";
|
||||||
import { Event, Emitter } from "@coder/events";
|
import { Event, Emitter } from "@coder/events";
|
||||||
|
import { logger } from "@coder/logger";
|
||||||
|
|
||||||
export interface PortScanner {
|
export interface PortScanner {
|
||||||
readonly ports: ReadonlyArray<number>;
|
readonly ports: ReadonlyArray<number>;
|
||||||
|
@ -75,11 +76,13 @@ export const createPortScanner = (scanInterval: number = 250): PortScanner => {
|
||||||
let disposed: boolean = false;
|
let disposed: boolean = false;
|
||||||
|
|
||||||
const doInterval = (): void => {
|
const doInterval = (): void => {
|
||||||
scan(() => {
|
scan((error) => {
|
||||||
if (disposed) {
|
if (error) {
|
||||||
return;
|
logger.error(`Port scanning will not be available: ${error.message}.`);
|
||||||
|
disposed = true;
|
||||||
|
} else if (!disposed) {
|
||||||
|
lastTimeout = setTimeout(doInterval, scanInterval);
|
||||||
}
|
}
|
||||||
lastTimeout = setTimeout(doInterval, scanInterval);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue