message_handler: Hold the session instance
The message_handler was using `getSession()` to get the session of the
handler.
The session instance is valid until the handler is completed, so in
reality, it is reasonable for the handler to own the session instance.
In the ipmi stress test, it's found an issue that the session is marked
as inactive and gets removed from sessions_manager before the handler is
completed, so the `getSession()` will throw in `~Handler()` and an error
log is printed:
Async RMCP+ reply failed
The session at that time is actually valid.
Let the handler hold the session instance and do not call `getSession()`
every time it uses the session, so that it does not need to call
session_manager's `getSession()` in `~Handler()`.
There are cases that the Handler is created without calling
`updSessionData()`, inititalize the session in its constructor in such
cases.
Note that there will be following commits to address the `getSession()`
issue in others places.
Tested: With the following commits, there is no "Async RMCP+ reply
failed" logs anymore.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: Ief4cbf0237605f7a9b38d59acae42c86f046f792
diff --git a/message_handler.cpp b/message_handler.cpp
index 861d69f..f845228 100644
--- a/message_handler.cpp
+++ b/message_handler.cpp
@@ -43,7 +43,7 @@
void Handler::updSessionData(std::shared_ptr<Message>& inMessage)
{
- auto session = session::Manager::get().getSession(inMessage->bmcSessionID);
+ session = session::Manager::get().getSession(inMessage->bmcSessionID);
sessionID = inMessage->bmcSessionID;
inMessage->rcSessionID = session->getRCSessionID();
@@ -113,7 +113,6 @@
auto command = inMessage->getCommand();
if (inMessage->payloadType == PayloadType::IPMI)
{
- auto session = session::Manager::get().getSession(sessionID);
// Process PayloadType::IPMI only if ipmi is enabled or for sessionless
// or for session establisbment command
if (this->sessionID == session::sessionZero ||
@@ -167,8 +166,6 @@
void Handler::send(std::shared_ptr<Message> outMessage)
{
- auto session = session::Manager::get().getSession(sessionID);
-
// Flatten the packet
auto packet = parser::flatten(outMessage, sessionHeader, session);
@@ -178,15 +175,11 @@
void Handler::setChannelInSession() const
{
- auto session = session::Manager::get().getSession(sessionID);
-
session->channelPtr = channel;
}
void Handler::sendSOLPayload(const std::vector<uint8_t>& input)
{
- auto session = session::Manager::get().getSession(sessionID);
-
auto outMessage = std::make_shared<Message>();
outMessage->payloadType = PayloadType::SOL;
outMessage->payload = input;
@@ -201,8 +194,6 @@
void Handler::sendUnsolicitedIPMIPayload(uint8_t netfn, uint8_t cmd,
const std::vector<uint8_t>& output)
{
- auto session = session::Manager::get().getSession(sessionID);
-
auto outMessage = std::make_shared<Message>();
outMessage->payloadType = PayloadType::IPMI;
outMessage->isPacketEncrypted = session->isCryptAlgoEnabled();