portlist: fix "readdirent: no such file or directory" errors on Linux.
This could happen when a process disappeared while we were reading its
file descriptor list.
I was able to replicate the problem by running this in another
terminal:
while :; do for i in $(seq 10); do
/bin/true & done >&/dev/null; wait >&/dev/null;
done
And then running the portlist tests thousands of times.
Fixes #339.
Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
This commit is contained in:
@@ -110,6 +110,12 @@ func addProcesses(pl []Port) ([]Port, error) {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
// This can happen if the directory we're
|
||||
// reading disappears during the run. No big
|
||||
// deal.
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("addProcesses.readDir: %w", err)
|
||||
}
|
||||
@@ -155,6 +161,12 @@ func foreachPID(fn func(pidStr string) error) error {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
// This can happen if the directory we're
|
||||
// reading disappears during the run. No big
|
||||
// deal.
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("foreachPID.readdir: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user