Archived
1
0

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:
Asher 2019-03-25 18:26:10 -05:00
parent cdc40d36ff
commit d16c6aeb30
No known key found for this signature in database
GPG Key ID: 7BB4BA9C783D2BBC

View File

@ -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);
}
lastTimeout = setTimeout(doInterval, scanInterval);
});
};