From d16c6aeb30004e2862012dcd75592c27095996ba Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 25 Mar 2019 18:26:10 -0500 Subject: [PATCH] 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. --- packages/server/src/portScanner.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/server/src/portScanner.ts b/packages/server/src/portScanner.ts index 1bb580a5f..bd4ecaddc 100644 --- a/packages/server/src/portScanner.ts +++ b/packages/server/src/portScanner.ts @@ -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; @@ -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); } - lastTimeout = setTimeout(doInterval, scanInterval); }); };