From e2c6489c2c07ffb8bf9057df75f404f54f5d3d95 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 7 Jan 2020 16:00:41 -0500 Subject: [PATCH] Detect indefinitely broken session and mark it There are evidently scenarios where an orphaned object could be stuck in logging indefinitely. Place a cap and automatically mark the object if it suffers from this. Change-Id: I60733c1eabb56494ad848595b46240af82c186d3 --- pyghmi/ipmi/private/session.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyghmi/ipmi/private/session.py b/pyghmi/ipmi/private/session.py index d0132895..a29ca3e3 100644 --- a/pyghmi/ipmi/private/session.py +++ b/pyghmi/ipmi/private/session.py @@ -493,6 +493,7 @@ class Session(object): else: self.privlevel = 4 self.autopriv = True + self.logoutexpiry = None self.autokeepalive = keepalive self.maxtimeout = 3 # be aggressive about giving up on initial packet self.incommand = False @@ -595,6 +596,7 @@ class Session(object): self.authtype = 0 self.ipmiversion = 1.5 self.timeout = initialtimeout + (0.5 * random.random()) + self.logoutexpiry = _monotonic_time() + self._getmaxtimeout() self.seqlun = 0 # NOTE(jbjohnso): per IPMI table 5-4, software ids in the ipmi spec may # be 0x81 through 0x8d. We'll stick with 0x81 for now, @@ -755,6 +757,9 @@ class Session(object): timeout=None, callback=None): if not self.logged: + if (self.logoutexpiry is not None and + _monotonic_time() > self.logoutexpiry): + self._mark_broken() raise exc.IpmiException('Session no longer connected') self._cmdwait() if not self.logged: @@ -1005,6 +1010,7 @@ class Session(object): def _req_priv_level(self): self.logged = 1 + self.logoutexpiry = None response = self.raw_command(netfn=0x6, command=0x3b, data=[self.privlevel]) if response['code']: