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
|
||||
import * as netstat from "node-netstat";
|
||||
import { Event, Emitter } from "@coder/events";
|
||||
import { logger } from "@coder/logger";
|
||||
|
||||
export interface PortScanner {
|
||||
readonly ports: ReadonlyArray<number>;
|
||||
|
@ -75,11 +76,13 @@ export const createPortScanner = (scanInterval: number = 250): PortScanner => {
|
|||
let disposed: boolean = false;
|
||||
|
||||
const doInterval = (): void => {
|
||||
scan(() => {
|
||||
if (disposed) {
|
||||
return;
|
||||
}
|
||||
scan((error) => {
|
||||
if (error) {
|
||||
logger.error(`Port scanning will not be available: ${error.message}.`);
|
||||
disposed = true;
|
||||
} else if (!disposed) {
|
||||
lastTimeout = setTimeout(doInterval, scanInterval);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue