From 69b6c87c8acb5985eeb6c51679d4f2da04ad0fa3 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Wed, 22 Apr 2020 16:20:58 +0200 Subject: [PATCH] File Descriptor: Use try/except as a safety --- instana/fsm.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/instana/fsm.py b/instana/fsm.py index 1f5fd5b9..d3dc3243 100644 --- a/instana/fsm.py +++ b/instana/fsm.py @@ -148,11 +148,17 @@ def announce_sensor(self, e): # If we're on a system with a procfs if os.path.exists("/proc/"): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect((self.agent.options.agent_host, self.agent.options.agent_port)) - path = "/proc/%d/fd/%d" % (pid, sock.fileno()) - d.fd = sock.fileno() - d.inode = os.readlink(path) + try: + # In CentOS 7, some odd things can happen such as: + # PermissionError: [Errno 13] Permission denied: '/proc/6/fd/8' + # Use a try/except as a safety + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.agent.options.agent_host, self.agent.options.agent_port)) + path = "/proc/%d/fd/%d" % (pid, sock.fileno()) + d.fd = sock.fileno() + d.inode = os.readlink(path) + except: + logger.debug("Error generating file descriptor: ", exc_info=True) response = self.agent.announce(d)