From 7891e7856fb85cf768d15e7b6c50f4dbd0903c1f Mon Sep 17 00:00:00 2001
From: EdenGri <63317673+EdenGri@users.noreply.github.com>
Date: Wed, 28 Dec 2022 21:54:06 +0200
Subject: [PATCH] Fixed set mtu for deleted subintf due to late notification
 (#2571)

* Fixed set mtu for deleted subintf due to late notification
---
 cfgmgr/intfmgr.cpp | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp
index 9e30e1265f41..f0f4ec97fa78 100644
--- a/cfgmgr/intfmgr.cpp
+++ b/cfgmgr/intfmgr.cpp
@@ -447,8 +447,19 @@ std::string IntfMgr::setHostSubIntfMtu(const string &alias, const string &mtu, c
     }
     SWSS_LOG_INFO("subintf %s active mtu: %s", alias.c_str(), subifMtu.c_str());
     cmd << IP_CMD " link set " << shellquote(alias) << " mtu " << shellquote(subifMtu);
-    EXEC_WITH_ERROR_THROW(cmd.str(), res);
+    std::string cmd_str = cmd.str();
+    int ret = swss::exec(cmd_str, res);
 
+    if (ret && !isIntfStateOk(alias))
+    {
+        // Can happen when a SET notification on the PORT_TABLE in the State DB
+        // followed by a new DEL notification that send by portmgrd
+        SWSS_LOG_WARN("Setting mtu to %s netdev failed with cmd:%s, rc:%d, error:%s", alias.c_str(), cmd_str.c_str(), ret, res.c_str());
+    }
+    else if (ret)
+    {
+        throw runtime_error(cmd_str + " : " + res);
+    }
     return subifMtu;
 }
 
@@ -468,7 +479,7 @@ void IntfMgr::updateSubIntfAdminStatus(const string &alias, const string &admin)
                 continue;
             }
             std::vector<FieldValueTuple> fvVector;
-            string subintf_admin = setHostSubIntfAdminStatus(intf, m_subIntfList[intf].adminStatus, admin); 
+            string subintf_admin = setHostSubIntfAdminStatus(intf, m_subIntfList[intf].adminStatus, admin);
             m_subIntfList[intf].currAdminStatus = subintf_admin;
             FieldValueTuple fvTuple("admin_status", subintf_admin);
             fvVector.push_back(fvTuple);