diff options
author | chendianqiang <c.d_q@163.com> | 2021-11-07 19:53:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-07 13:53:57 +0200 |
commit | a527c3e8148881c4a33b2c78ba1cb0889b4893fc (patch) | |
tree | cdf70c86fee46e635703760c717703067552b4ed /tests/support/util.tcl | |
parent | 79ac57561f268814babe212c9216efe45cfdf937 (diff) | |
download | redis-a527c3e8148881c4a33b2c78ba1cb0889b4893fc.tar.gz |
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>
Diffstat (limited to 'tests/support/util.tcl')
-rw-r--r-- | tests/support/util.tcl | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/support/util.tcl b/tests/support/util.tcl index 60a5bb87b..d6f8fc062 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -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 ::last_port_attempted $port - return $port - } else { - catch { + 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 - close $fd2 } + } else { + close $fd1 + close $fd2 + set ::last_port_attempted $port + return $port } incr port } |