From e119885a2f895391e1237f26c2520185b8d3a196 Mon Sep 17 00:00:00 2001 From: Mykola Kobets Date: Mon, 27 Jul 2026 18:04:53 +0300 Subject: [PATCH 1/3] cm: launcher: double the amount of gid-s uid-s for instance removal Signed-off-by: Mykola Kobets Reviewed-by: Mykhailo Lohvynenko Reviewed-by: Oleksandr Grytsov --- src/core/cm/launcher/idpool.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/cm/launcher/idpool.hpp b/src/core/cm/launcher/idpool.hpp index 7d8fdbcd7..d2cb5868a 100644 --- a/src/core/cm/launcher/idpool.hpp +++ b/src/core/cm/launcher/idpool.hpp @@ -28,8 +28,9 @@ static constexpr auto cGIDRangeEnd = 10000; /** * Max number of locked GIDs simultaneously. + * Double the number of update items to avoid exhausting the range when removing instances. */ -static constexpr auto cMaxNumLockedGIDs = cMaxNumUpdateItems; +static constexpr auto cMaxNumLockedGIDs = 2 * cMaxNumUpdateItems; /** * UID range start. @@ -43,8 +44,9 @@ static constexpr auto cUIDRangeEnd = 10000; /** * Max number of locked UIDs simultaneously. + * Double the number of update items to avoid exhausting the range when removing instances. */ -static constexpr auto cMaxNumLockedUIDs = cMaxNumInstances; +static constexpr auto cMaxNumLockedUIDs = 2 * cMaxNumInstances; /** * Pool that manages identifiers with reference counting per key. @@ -166,10 +168,9 @@ class IDPool { StaticMap mItems; }; -using GIDPool - = IDPool, gid_t, cGIDRangeBegin, cGIDRangeEnd, cMaxNumLockedGIDs, cMaxNumUpdateItems>; +using GIDPool = IDPool, gid_t, cGIDRangeBegin, cGIDRangeEnd, cMaxNumLockedGIDs, cMaxNumLockedGIDs>; -using UIDPool = IDPool; +using UIDPool = IDPool; } // namespace aos::cm::launcher From 9f34205fa5fcac55d49d4ee7e0f0b66ceb0a53e8 Mon Sep 17 00:00:00 2001 From: Mykola Kobets Date: Mon, 27 Jul 2026 17:57:54 +0300 Subject: [PATCH 2/3] cm: launcher: fix crash in cm::launcher nullptr returned with eNoError, which caused a crash in IsSubjectEnabled Signed-off-by: Mykola Kobets Reviewed-by: Mykhailo Lohvynenko Reviewed-by: Oleksandr Grytsov --- src/core/cm/launcher/instancemanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/cm/launcher/instancemanager.cpp b/src/core/cm/launcher/instancemanager.cpp index 9773fefe9..e69b57c3e 100644 --- a/src/core/cm/launcher/instancemanager.cpp +++ b/src/core/cm/launcher/instancemanager.cpp @@ -563,11 +563,11 @@ RetWithError> InstanceManager::CreateInstance(const Instance if (auto err = newInstance->Init(); !err.IsNone()) { // Do not leave invalid instance in storage. - if (err = newInstance->Remove(); !err.IsNone()) { - LOG_ERR() << "Can't remove instance" << Log::Field(err); + if (auto rmErr = newInstance->Remove(); !rmErr.IsNone()) { + LOG_ERR() << "Can't remove instance" << Log::Field(AOS_ERROR_WRAP(rmErr)); } - return {{}, AOS_ERROR_WRAP(err)}; + return {nullptr, err}; } if (auto [_, err] = newInstance->OverrideEnvVars(mEnvVarsOverrides); !err.IsNone()) { From a47820eb6b1e6167f5e460f3b2be93c1a1cf1401 Mon Sep 17 00:00:00 2001 From: Mykola Kobets Date: Mon, 27 Jul 2026 18:17:50 +0300 Subject: [PATCH 3/3] cm: launcher: release id pool even storage RemoveInstance failed Signed-off-by: Mykola Kobets Reviewed-by: Mykhailo Lohvynenko Reviewed-by: Oleksandr Grytsov --- src/core/cm/launcher/instance.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core/cm/launcher/instance.cpp b/src/core/cm/launcher/instance.cpp index a92bb2f85..48fbf62a7 100644 --- a/src/core/cm/launcher/instance.cpp +++ b/src/core/cm/launcher/instance.cpp @@ -408,24 +408,32 @@ Error ServiceInstance::Remove() { LOG_DBG() << "Remove instance" << Log::Field("instanceID", mInfo.mInstanceIdent); + Error firstErr = ErrorEnum::eNone; + if (auto err = mStorageState.Remove(mInfo.mInstanceIdent); !err.IsNone() && !err.Is(ErrorEnum::eNotFound)) { - return AOS_ERROR_WRAP(err); + firstErr = AOS_ERROR_WRAP(err); } if (auto err = mStorage.RemoveInstance(mInfo.mInstanceIdent, mInfo.mVersion); !err.IsNone() && !err.Is(ErrorEnum::eNotFound)) { - return AOS_ERROR_WRAP(err); + if (firstErr.IsNone()) { + firstErr = AOS_ERROR_WRAP(err); + } } if (auto err = mUIDPool.Release(mInfo.mInstanceIdent); !err.IsNone() && !err.Is(ErrorEnum::eNotFound)) { - return AOS_ERROR_WRAP(err); + if (firstErr.IsNone()) { + firstErr = AOS_ERROR_WRAP(err); + } } if (auto err = mGIDPool.Release(mInfo.mInstanceIdent.mItemID); !err.IsNone() && !err.Is(ErrorEnum::eNotFound)) { - return AOS_ERROR_WRAP(err); + if (firstErr.IsNone()) { + firstErr = AOS_ERROR_WRAP(err); + } } - return ErrorEnum::eNone; + return firstErr; } Error ServiceInstance::Cache(bool disable)