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: chendianqiang <chendianqiang@meituan.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
This commit is contained in:
chendianqiang 2021-11-07 19:53:57 +08:00 committed by GitHub
parent 79ac57561f
commit a527c3e814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -443,15 +443,17 @@ proc find_available_port {start count} {
if {$port < $start || $port >= $start+$count} {
set port $start
}
if {[catch {set fd1 [socket 127.0.0.1 $port]}] &&
[catch {set fd2 [socket 127.0.0.1 [expr $port+10000]]}]} {
set fd1 -1
if {[catch {set fd1 [socket -server 127.0.0.1 $port]}] ||
[catch {set fd2 [socket -server 127.0.0.1 [expr $port+10000]]}]} {
if {$fd1 != -1} {
close $fd1
}
} else {
close $fd1
close $fd2
set ::last_port_attempted $port
return $port
} else {
catch {
close $fd1
close $fd2
}
}
incr port
}