From 31c797c22141aec9942a615fc714d89bfdc8d093 Mon Sep 17 00:00:00 2001 From: Jarrod Johnon Date: Thu, 22 Jan 2015 15:46:21 -0500 Subject: [PATCH] Correct redundant timedout calls in recursion When handling multiple sessions hiting a timeout expiry, there was a chance that during recursion a session would get redundantly scheduled for retry/timeout. Address this by clearing out the scheduled sessions prior to acting on any of the sessions. Additionally, only start the timeout clock after successfully placing the payload on the wire, rather than including local delays against timeout expiry. Change-Id: I2f58f0afcb13943654489630f7e8164913633a49 --- pyghmi/ipmi/private/session.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pyghmi/ipmi/private/session.py b/pyghmi/ipmi/private/session.py index b3940c3e..139b6806 100644 --- a/pyghmi/ipmi/private/session.py +++ b/pyghmi/ipmi/private/session.py @@ -998,6 +998,9 @@ class Session(object): # to avoid confusing the for loop for session in sessionstodel: cls.waiting_sessions.pop(session, None) + # one loop iteration to make sure recursion doesn't induce redundant + # timeouts + for session in sessionstodel: session._timedout() return len(cls.waiting_sessions) @@ -1474,11 +1477,6 @@ class Session(object): if self.sequencenumber: # seq number of zero will be left alone, it is # special, otherwise increment self.sequencenumber += 1 - if retry: - Session.waiting_sessions[self] = {} - Session.waiting_sessions[self]['ipmisession'] = self - Session.waiting_sessions[self]['timeout'] = self.timeout + \ - _monotonic_time() if delay_xmit is not None: Session.waiting_sessions[self]['timeout'] = delay_xmit + \ _monotonic_time() @@ -1506,6 +1504,11 @@ class Session(object): except socket.gaierror: raise exc.IpmiException( "Unable to transmit to specified address") + if retry: + Session.waiting_sessions[self] = {} + Session.waiting_sessions[self]['ipmisession'] = self + Session.waiting_sessions[self]['timeout'] = self.timeout + \ + _monotonic_time() def logout(self): if not self.logged: