Skip to content

RSDK-11067: remove resource on alwaysrebuild #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/viam/sdk/module/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -129,16 +130,18 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
}

const std::shared_ptr<const ModelRegistration> reg =
Registry::get().lookup_model(cfg.name());
Registry::get().lookup_model(cfg.api(), cfg.model());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you fail to look up the model registration here, I think you should return an error. It's a pretty strange state of affairs because the model was registered once, apparently, such that the object could be brought into existence (otherwise, what is being reconfigured?) but now that it is time to reconfigure by rebuilding, the registration is gone. That also would have made the error here obvious, rather than a silent misbehavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, it was really confusing to debug


// TODO RSDK-11067 new resource gets constructed while old one is still alive.
if (reg) {
try {
const std::shared_ptr<Resource> 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> 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();
Expand Down
5 changes: 3 additions & 2 deletions src/viam/sdk/resource/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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> resource) {
const std::lock_guard<std::mutex> lock(lock_);
Expand Down