Skip to content

Commit 7011615

Browse files
author
Victoria Hall
committed
checking only 25 ports
1 parent 994dd84 commit 7011615

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/http/httpProxy.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { HttpResponse } from './HttpResponse';
1313
const requests: Record<string, http.IncomingMessage> = {};
1414
const responses: Record<string, http.ServerResponse> = {};
1515
const minPort = 55000;
16-
const maxPort = 65535;
16+
const maxPort = 55025;
1717

1818
const invocRequestEmitter = new EventEmitter();
1919

@@ -137,20 +137,21 @@ export async function setupHttpProxy(): Promise<string> {
137137
});
138138
}
139139

140-
// Function to get a random port within a specified range
141-
function getRandomPort(): number {
142-
return Math.floor(Math.random() * (maxPort - minPort + 1)) + minPort;
143-
}
144-
145140
// Function to find an open port starting from a specified port
146141
function findOpenPort(callback: (port: number) => void): void {
147142
const server = net.createServer();
148143

149144
function tryPort(port: number) {
145+
if (port > maxPort) {
146+
// If we've reached the maximum port, throw an error
147+
throw new AzFuncSystemError(
148+
`No available ports found between ${minPort} and ${maxPort}. To enable HTTP streaming, please open a port in this range.`
149+
);
150+
}
151+
150152
server.once('error', () => {
151-
// If the port is unavailable, get a random port and try again
152-
const randomPort = getRandomPort();
153-
tryPort(randomPort);
153+
// If the port is unavailable, increment and try the next one
154+
tryPort(port + 1);
154155
});
155156

156157
// If the port is available, return it

0 commit comments

Comments
 (0)