From 73ce67150c8b1888251bbc19cde1b69b48194245 Mon Sep 17 00:00:00 2001 From: Vadym Chepkov Date: Sun, 24 Nov 2024 09:08:51 -0500 Subject: [PATCH] fix: prevent random failures in agent_status_check The list of files in /proc/[0-9]*/cmdline can change as processes start or terminate between the Dir.glob and File.read operations --- lib/facter/agent_status_check.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/facter/agent_status_check.rb b/lib/facter/agent_status_check.rb index 88f7d46f..f2252b35 100644 --- a/lib/facter/agent_status_check.rb +++ b/lib/facter/agent_status_check.rb @@ -31,7 +31,11 @@ socket_matches = Set.new(socket_state.scan(%r{ino:(\d+)}).flatten) # Look for the pxp-agent process in the process table: - cmdline_path = Dir.glob('/proc/[0-9]*/cmdline').find { |path| File.read(path).split("\0").first == '/opt/puppetlabs/puppet/bin/pxp-agent' } + cmdline_path = Dir.glob('/proc/[0-9]*/cmdline').find do |path| + File.read(path).split("\0").first == '/opt/puppetlabs/puppet/bin/pxp-agent' + rescue Errno::ENOENT + next + end # If no match was found, then the connection to 8142 is not the pxp-agent process because it is not in the process table: if cmdline_path.nil?