File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -988,12 +988,19 @@ def _get_unused_port(self, allocated_ports=None):
988988 s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
989989 s .bind (("" , 0 ))
990990 port = s .getsockname ()[1 ]
991+ low_end = ray_constants .env_integer ("RAY_PORT_RANGE_LOW" , port )
992+ high_end = ray_constants .env_integer ("RAY_PORT_RANGE_HIGH" , 65535 )
993+ if low_end > high_end :
994+ raise ValueError (
995+ f"Invalid port range: RAY_PORT_RANGE_LOW ({ low_end } ) must be less than or equal to RAY_PORT_RANGE_HIGH ({ high_end } )."
996+ )
991997
992- # Try to generate a port that is far above the 'next available' one.
993- # This solves issue #8254 where GRPC fails because the port assigned
994- # from this method has been used by a different process.
998+ # Try to generate a port that is far above the 'next available' one
999+ # or from a given range(if low_end and high_end is defined). This
1000+ # solves issue #8254 where GRPC fails because the port assigned from
1001+ # this method has been used by a different process.
9951002 for _ in range (ray_constants .NUM_PORT_RETRIES ):
996- new_port = random .randint (port , 65535 )
1003+ new_port = random .randint (low_end , high_end )
9971004 if new_port in allocated_ports :
9981005 # This port is allocated for other usage already,
9991006 # so we shouldn't use it even if it's not in use right now.
You can’t perform that action at this time.
0 commit comments