Unverified Commit a527c3e8 authored by chendianqiang's avatar chendianqiang Committed by GitHub
Browse files

Test suite - user server socket to optimize port detection (#9663)



Optimized port detection for tcl, use 'socket -server' instead of 'socket' to rule out port on TIME_WAIT
Co-authored-by: default avatarchendianqiang <chendianqiang@meituan.com>
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
parent 79ac5756
...@@ -443,15 +443,17 @@ proc find_available_port {start count} { ...@@ -443,15 +443,17 @@ proc find_available_port {start count} {
if {$port < $start || $port >= $start+$count} { if {$port < $start || $port >= $start+$count} {
set port $start set port $start
} }
if {[catch {set fd1 [socket 127.0.0.1 $port]}] && set fd1 -1
[catch {set fd2 [socket 127.0.0.1 [expr $port+10000]]}]} { if {[catch {set fd1 [socket -server 127.0.0.1 $port]}] ||
set ::last_port_attempted $port [catch {set fd2 [socket -server 127.0.0.1 [expr $port+10000]]}]} {
return $port if {$fd1 != -1} {
close $fd1
}
} else { } else {
catch {
close $fd1 close $fd1
close $fd2 close $fd2
} set ::last_port_attempted $port
return $port
} }
incr port incr port
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment