@@ -13,7 +13,7 @@ import { HttpResponse } from './HttpResponse';
1313const requests : Record < string , http . IncomingMessage > = { } ;
1414const responses : Record < string , http . ServerResponse > = { } ;
1515const minPort = 55000 ;
16- const maxPort = 65535 ;
16+ const maxPort = 55025 ;
1717
1818const 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
146141function 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