From d489b151fb83e458fe9aac7d96e40b8d92844a09 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 16 May 2017 13:54:59 -0400 Subject: [PATCH] Do not reuse an expired session If a caller does not do a keepalive, but instead creates new Command objects or similar, accomodate by ditching the session that was not kept alive rather than trying to use it. Change-Id: I94fba08e3b2c03862b053c11aa3ee6b810db6f21 --- pyghmi/ipmi/private/session.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pyghmi/ipmi/private/session.py b/pyghmi/ipmi/private/session.py index 6997c195..e67437f6 100644 --- a/pyghmi/ipmi/private/session.py +++ b/pyghmi/ipmi/private/session.py @@ -372,6 +372,15 @@ class Session(object): # is given in the same thread as was called return + @classmethod + def _is_session_valid(cls, session): + sess = cls.keepalive_sessions.get(session, None) + if sess is not None and 'timeout' in sess: + if sess['timeout'] < _monotonic_time(): + # session would have timed out by now, don't use it + return False + return True + def __new__(cls, bmc, userid, @@ -390,7 +399,8 @@ class Session(object): self = cls.bmc_handlers[sockaddr] if (self.bmc == bmc and self.userid == userid and self.password == password and self.kgo == kg and - (self.logged or self.logging)): + (self.logged or self.logging) and + cls._is_session_valid(self)): trueself = self else: del cls.bmc_handlers[sockaddr]