diff --git a/src/viam/sdk/module/service.cpp b/src/viam/sdk/module/service.cpp index 658630484..530165b84 100644 --- a/src/viam/sdk/module/service.cpp +++ b/src/viam/sdk/module/service.cpp @@ -83,7 +83,8 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service { } catch (const std::exception& exc) { return grpc::Status(::grpc::INTERNAL, exc.what()); } - }; + } + try { parent.server_->add_resource(res, ctx->deadline()); } catch (const std::exception& exc) { @@ -129,16 +130,18 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service { } const std::shared_ptr reg = - Registry::get().lookup_model(cfg.name()); + Registry::get().lookup_model(cfg.api(), cfg.model()); - // TODO RSDK-11067 new resource gets constructed while old one is still alive. - if (reg) { - try { - const std::shared_ptr resource = reg->construct_resource(deps, cfg); - manager->replace_one(cfg.resource_name(), resource); - } catch (const std::exception& exc) { - return grpc::Status(::grpc::INTERNAL, exc.what()); - } + if (!reg) { + return grpc::Status(::grpc::INTERNAL, + "Unable to rebuild resource: model registration not found"); + } + + try { + std::shared_ptr resource = reg->construct_resource(deps, cfg); + manager->replace_one(cfg.resource_name(), std::move(resource)); + } catch (const std::exception& exc) { + return grpc::Status(::grpc::INTERNAL, exc.what()); } return grpc::Status(); diff --git a/src/viam/sdk/resource/resource_manager.cpp b/src/viam/sdk/resource/resource_manager.cpp index b11d9b61a..3c62faae7 100644 --- a/src/viam/sdk/resource/resource_manager.cpp +++ b/src/viam/sdk/resource/resource_manager.cpp @@ -108,6 +108,7 @@ void ResourceManager::do_remove(const Name& name) { ErrorCondition::k_resource_not_found, "Attempted to remove resource " + name.to_string() + " but it didn't exist!"); } + resources_.erase(short_name); std::string const shortcut = get_shortcut_name(short_name); @@ -135,8 +136,8 @@ void ResourceManager::remove(const Name& name) { do_remove(name); } catch (std::exception& exc) { VIAM_SDK_LOG(error) << "unable to remove resource: " << exc.what(); - }; -}; + } +} void ResourceManager::replace_one(const Name& name, std::shared_ptr resource) { const std::lock_guard lock(lock_);