From 871984bde026b14d2a24bac191342101bc488ca8 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 16 Feb 2015 13:41:42 -0500 Subject: [PATCH] Handle concurrent session requests A caller may end up making requests that would get gathered into a single session object. However due to being aggressive, a second session object supersedes the original without the original getting a chance to complete login and satisfy the second caller. Address this by reusing a 'logging' session and then having __init__ follow the state of the other session object already in progress. Without this a caller can end up provoking a fight and having the BMC refuse to continue to entertain the shenanigans in short order. Change-Id: I47acbc0c974900ff50c02d470b5a79a3fed9bb73 --- pyghmi/ipmi/private/session.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyghmi/ipmi/private/session.py b/pyghmi/ipmi/private/session.py index 1cc9b441..f3352544 100644 --- a/pyghmi/ipmi/private/session.py +++ b/pyghmi/ipmi/private/session.py @@ -336,7 +336,7 @@ 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): + (self.logged or self.logging)): trueself = self else: del cls.bmc_handlers[sockaddr] @@ -404,7 +404,7 @@ class Session(object): self.socket = self._assignsocket() self.login() if not self.async: - while not self.logged: + while self.logging and not self.logged: Session.wait_for_rsp() def _mark_broken(self): @@ -412,6 +412,7 @@ class Session(object): # deregister our keepalive facility Session.keepalive_sessions.pop(self, None) Session.waiting_sessions.pop(self, None) + self.logging = False if self.logged: self.logged = 0 # mark session as busted self._customkeepalives = None @@ -460,6 +461,7 @@ class Session(object): # do not forsee a reason to adjust self.rqaddr = 0x81 + self.logging = True self.logged = 0 # NOTE(jbjohnso): when we confirm a working sockaddr, put it here to # skip getaddrinfo @@ -850,6 +852,7 @@ class Session(object): self.onlogon({'error': errstr}) return self.logged = 1 + self.logging = False Session.keepalive_sessions[self] = {} Session.keepalive_sessions[self]['ipmisession'] = self Session.keepalive_sessions[self]['timeout'] = _monotonic_time() + \ @@ -1528,6 +1531,7 @@ class Session(object): # stop trying for a keepalive, Session.keepalive_sessions.pop(self, None) self.logged = 0 + self.logging = False self._customkeepalives = None self.nowait = False self.socketpool[self.socket] -= 1