Unverified Commit 8c42d125 authored by Yossi Gottlieb's avatar Yossi Gottlieb Committed by GitHub
Browse files

Fix errors with sentinel leaked fds test. (#8482)



* Don't run test script on non-Linux.
* Verify that reported fds do indeed exist also in parent, to avoid
  false negatives on some systems (namely CentOS).
Co-authored-by: default avatarAndy Pan <panjf2000@gmail.com>
parent 94bc26e6
...@@ -21,6 +21,16 @@ proc get_parent_pid {_pid} { ...@@ -21,6 +21,16 @@ proc get_parent_pid {_pid} {
error "failed to get parent pid" error "failed to get parent pid"
} }
# Read symlink to get info about the specified fd of the specified process.
# The result can be the file name or an arbitrary string that identifies it.
# When not able to read, an empty string is returned.
proc get_fdlink {_pid fd} {
if { [catch {set fdlink [file readlink "/proc/$_pid/fd/$fd"]} err] } {
return ""
}
return $fdlink
}
# Linux only # Linux only
set os [exec uname] set os [exec uname]
if {$os != "Linux"} { if {$os != "Linux"} {
...@@ -46,17 +56,16 @@ foreach fd [glob -tails -directory "/proc/self/fd" *] { ...@@ -46,17 +56,16 @@ foreach fd [glob -tails -directory "/proc/self/fd" *] {
continue continue
} }
# Read symlink to get info about the file descriptor. This can be a real set fdlink [get_fdlink "self" $fd]
# file name or an arbitrary string that identifies the fd. if {$fdlink == ""} {
if { [catch {set fdlink [file readlink "/proc/self/fd/$fd"]} err] } {
continue continue
} }
# See if grandparent process has the same fd and info and skip if it does. # We ignore fds that existed in the grandparent, or fds that don't exist
if { ! [catch {set gp_fdlink [file readlink "/proc/$grandparent_pid/fd/$fd"]} err] } { # in our parent (Sentinel process).
if {$gp_fdlink == $fdlink} { if {[get_fdlink $grandparent_pid $fd] == $fdlink ||
continue [get_fdlink $parent_pid $fd] != $fdlink} {
} continue
} }
lappend leaked_fds [list $fd $fdlink] lappend leaked_fds [list $fd $fdlink]
......
...@@ -41,7 +41,7 @@ test "(init) Sentinels can start monitoring a master" { ...@@ -41,7 +41,7 @@ test "(init) Sentinels can start monitoring a master" {
S $id SENTINEL SET mymaster down-after-milliseconds 2000 S $id SENTINEL SET mymaster down-after-milliseconds 2000
S $id SENTINEL SET mymaster failover-timeout 20000 S $id SENTINEL SET mymaster failover-timeout 20000
S $id SENTINEL SET mymaster parallel-syncs 10 S $id SENTINEL SET mymaster parallel-syncs 10
if {$::leaked_fds_file != ""} { if {$::leaked_fds_file != "" && [exec uname] == "Linux"} {
S $id SENTINEL SET mymaster notification-script ../../tests/helpers/check_leaked_fds.tcl S $id SENTINEL SET mymaster notification-script ../../tests/helpers/check_leaked_fds.tcl
S $id SENTINEL SET mymaster client-reconfig-script ../../tests/helpers/check_leaked_fds.tcl S $id SENTINEL SET mymaster client-reconfig-script ../../tests/helpers/check_leaked_fds.tcl
} }
......
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