From 5aec0e69f5a9d26cc6c1f98e4252b10fe4449662 Mon Sep 17 00:00:00 2001 From: Markus Hilger Date: Fri, 14 Aug 2026 14:07:49 +0200 Subject: [PATCH] Recognise a session that is already open to the same bmc The check for sharing a live session compared the credentials a session keeps encoded against the strings every caller passes, so it never matched and each caller built another session beside the one it could not see. Normalise both sides. Three commands to one bmc went from three sessions on three sockets to one, and from five sessions open on the bmc to three. Not from the port to asyncio: upstream compares the same two things the same way. --- .../aiohmi/ipmi/private/session.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/confluent_server/aiohmi/ipmi/private/session.py b/confluent_server/aiohmi/ipmi/private/session.py index a13d9cb3..6dfc0a1a 100644 --- a/confluent_server/aiohmi/ipmi/private/session.py +++ b/confluent_server/aiohmi/ipmi/private/session.py @@ -251,6 +251,18 @@ async def _poller(timeout=0): return sessionqueue +def _credkey(value): + """A credential in the form a session keeps it, so callers can be compared + + A session encodes what it was given, while the checks for sharing one are + built from whatever the caller passed. Put both through here. + """ + try: + return value.encode('utf-8') + except AttributeError: + return value + + def _aespad(data): """ipmi demands a certain pad scheme, per table 13-20 AES-CBC encrypted @@ -450,7 +462,7 @@ class Session(object): keepalive=True): trueself = None forbidsock = [] - sesskey = (bmc, userid, password, port, kg) + sesskey = (bmc, _credkey(userid), _credkey(password), port, kg) for res in socket.getaddrinfo(bmc, port, 0, socket.SOCK_DGRAM): sockaddr = res[4] if ipv6support and res[0] == socket.AF_INET: @@ -466,8 +478,8 @@ class Session(object): del cls.bmc_handlers[sockaddr][portself[0]] continue if (self.bmc == bmc - and self.userid == userid - and self.password == password + and self.userid == _credkey(userid) + and self.password == _credkey(password) and self.kgo == kg): trueself = self break