sol: Handle deactivate payload correctly when session is closed

Resolves openbmc/openbmc#1781
Resolves openbmc/openbmc#2053

Change-Id: Iabb61fc510d33a4132e7ad07184eb8847301b686
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/command/payload_cmds.cpp b/command/payload_cmds.cpp
index 2020722..0cc52cc 100644
--- a/command/payload_cmds.cpp
+++ b/command/payload_cmds.cpp
@@ -127,13 +127,28 @@
                 (request->payloadInstance);
         auto sessionID = context.sessionID;
 
-        activating(request->payloadInstance, sessionID);
         std::get<sol::Manager&>(singletonPool).stopPayloadInstance(
                 request->payloadInstance);
 
+        try
+        {
+            activating(request->payloadInstance, sessionID);
+        }
+        catch (std::exception& e)
+        {
+            log<level::INFO>(e.what());
+            /*
+             * In case session has been closed (like in the case of inactivity
+             * timeout), then activating function would throw an exception,
+             * since sessionID is not found. IPMI success completion code is
+             * returned, since the session is closed.
+             */
+            return outPayload;
+        }
+
         auto check = std::get<session::Manager&>(singletonPool).stopSession
                 (sessionID);
-        if(!check)
+        if (!check)
         {
             response->completionCode = IPMI_CC_UNSPECIFIED_ERROR;
         }
diff --git a/sessions_manager.cpp b/sessions_manager.cpp
index 18c96ba..ee4a35f 100644
--- a/sessions_manager.cpp
+++ b/sessions_manager.cpp
@@ -126,6 +126,7 @@
             {
                 return iter->second;
             }
+            break;
         }
         case RetrieveOption::RC_SESSION_ID:
         {
@@ -142,6 +143,7 @@
             {
                 return iter->second;
             }
+            break;
         }
         default:
             throw std::runtime_error("Invalid retrieval option");