Skip to content

Commit d16c6ae

Browse files
committed
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.
1 parent cdc40d3 commit d16c6ae

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/server/src/portScanner.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ts-ignore
22
import * as netstat from "node-netstat";
33
import { Event, Emitter } from "@coder/events";
4+
import { logger } from "@coder/logger";
45

56
export interface PortScanner {
67
readonly ports: ReadonlyArray<number>;
@@ -75,11 +76,13 @@ export const createPortScanner = (scanInterval: number = 250): PortScanner => {
7576
let disposed: boolean = false;
7677

7778
const doInterval = (): void => {
78-
scan(() => {
79-
if (disposed) {
80-
return;
79+
scan((error) => {
80+
if (error) {
81+
logger.error(`Port scanning will not be available: ${error.message}.`);
82+
disposed = true;
83+
} else if (!disposed) {
84+
lastTimeout = setTimeout(doInterval, scanInterval);
8185
}
82-
lastTimeout = setTimeout(doInterval, scanInterval);
8386
});
8487
};
8588

0 commit comments

Comments
 (0)