2
0
mirror of https://opendev.org/x/pyghmi synced 2025-01-28 11:57:34 +00:00

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
This commit is contained in:
Jarrod Johnson 2017-05-16 13:54:59 -04:00
parent 4c366d2f47
commit d489b151fb

View File

@ -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]