@@ -12,6 +12,8 @@ import { HttpResponse } from './HttpResponse';
1212
1313const requests : Record < string , http . IncomingMessage > = { } ;
1414const responses : Record < string , http . ServerResponse > = { } ;
15+ const minPort = 55000 ;
16+ const maxPort = 65535 ;
1517
1618const invocRequestEmitter = new EventEmitter ( ) ;
1719
@@ -111,7 +113,7 @@ export async function setupHttpProxy(): Promise<string> {
111113 if ( address . port === 0 ) {
112114 // Auto-assigned port is 0, find and bind to an open port
113115 workerSystemLog ( 'debug' , `Port 0 assigned. Finding open port.` ) ;
114- findOpenPort ( 51929 , ( openPort : number ) => {
116+ findOpenPort ( ( openPort : number ) => {
115117 // Close the server and re-listen on the found open port
116118 server . close ( ) ;
117119 server . listen ( openPort , ( ) => {
@@ -136,12 +138,12 @@ export async function setupHttpProxy(): Promise<string> {
136138}
137139
138140// Function to get a random port within a specified range
139- function getRandomPort ( minPort = 55000 , maxPort = 65535 ) : number {
141+ function getRandomPort ( ) : number {
140142 return Math . floor ( Math . random ( ) * ( maxPort - minPort + 1 ) ) + minPort ;
141143}
142144
143145// Function to find an open port starting from a specified port
144- function findOpenPort ( startingPort : number , callback : ( port : number ) => void ) : void {
146+ function findOpenPort ( callback : ( port : number ) => void ) : void {
145147 const server = net . createServer ( ) ;
146148
147149 function tryPort ( port : number ) {
@@ -166,5 +168,5 @@ function findOpenPort(startingPort: number, callback: (port: number) => void): v
166168 }
167169
168170 // Start trying from the specified starting port
169- tryPort ( startingPort ) ;
171+ tryPort ( minPort ) ;
170172}
0 commit comments