Skip to content

Commit 0394a92

Browse files
authored
File Descriptor: Use try/except as a safety (#226)
1 parent e584006 commit 0394a92

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

instana/fsm.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,17 @@ def announce_sensor(self, e):
148148

149149
# If we're on a system with a procfs
150150
if os.path.exists("/proc/"):
151-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
152-
sock.connect((self.agent.options.agent_host, self.agent.options.agent_port))
153-
path = "/proc/%d/fd/%d" % (pid, sock.fileno())
154-
d.fd = sock.fileno()
155-
d.inode = os.readlink(path)
151+
try:
152+
# In CentOS 7, some odd things can happen such as:
153+
# PermissionError: [Errno 13] Permission denied: '/proc/6/fd/8'
154+
# Use a try/except as a safety
155+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
156+
sock.connect((self.agent.options.agent_host, self.agent.options.agent_port))
157+
path = "/proc/%d/fd/%d" % (pid, sock.fileno())
158+
d.fd = sock.fileno()
159+
d.inode = os.readlink(path)
160+
except:
161+
logger.debug("Error generating file descriptor: ", exc_info=True)
156162

157163
response = self.agent.announce(d)
158164

0 commit comments

Comments
 (0)