Skip to content

Commit

Permalink
Fix Rockets deadlock in plugins
Browse files Browse the repository at this point in the history
A deadlock can appear when doing scene modifications with callbacks to rockets in a plugin method that was initially called from rockets. Fixed by adding the proper scope guards.
  • Loading branch information
Jonas Karlsson committed Feb 5, 2019
1 parent 2ee7e71 commit c2421d0
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions plugins/Rockets/RocketsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ class RocketsPlugin::Impl : public ActionInterface
const PropertyMap& input,
const std::function<void(PropertyMap)>& action)
{
_jsonrpcServer->connect(desc.methodName, [action](const auto& request) {
_jsonrpcServer->connect(desc.methodName, [action,
this](const auto& request) {
ScopedCurrentClient scope(this->_currentClientID, request.clientID);
action(jsonToPropertyMap(request.message));
});

Expand All @@ -275,7 +277,11 @@ class RocketsPlugin::Impl : public ActionInterface
void registerNotification(const RpcDescription& desc,
const std::function<void()>& action)
{
_jsonrpcServer->connect(desc.methodName, [action] { action(); });
_jsonrpcServer->connect(desc.methodName, [action,
this](const auto& request) {
ScopedCurrentClient scope(this->_currentClientID, request.clientID);
action();
});

_handleSchema(desc.methodName, buildJsonRpcSchemaNotify(desc));
}
Expand All @@ -284,8 +290,9 @@ class RocketsPlugin::Impl : public ActionInterface
const PropertyMap& input, const PropertyMap& output,
const std::function<PropertyMap(PropertyMap)>& action)
{
_bindEndpoint(desc.methodName, [ name = desc.methodName,
action ](const auto& request) {
_bindEndpoint(desc.methodName, [ name = desc.methodName, action,
this ](const auto& request) {
ScopedCurrentClient scope(this->_currentClientID, request.clientID);
try
{
return Response{
Expand All @@ -307,7 +314,9 @@ class RocketsPlugin::Impl : public ActionInterface
void registerRequest(const RpcDescription& desc, const PropertyMap& output,
const std::function<PropertyMap()>& action)
{
_jsonrpcServer->bind(desc.methodName, [action](const auto&) {
_jsonrpcServer->bind(desc.methodName, [action,
this](const auto& request) {
ScopedCurrentClient scope(this->_currentClientID, request.clientID);
return Response{to_json(action())};
});

Expand All @@ -317,28 +326,34 @@ class RocketsPlugin::Impl : public ActionInterface

void _registerRequest(const std::string& name, const RetParamFunc& action)
{
_jsonrpcServer->bind(name, [action](const auto& request) {
_jsonrpcServer->bind(name, [action, this](const auto& request) {
ScopedCurrentClient scope(this->_currentClientID, request.clientID);
return Response{action(request.message)};
});
}

void _registerRequest(const std::string& name, const RetFunc& action)
{
_jsonrpcServer->bind(name, [action](const auto&) {
_jsonrpcServer->bind(name, [action, this](const auto& request) {
ScopedCurrentClient scope(this->_currentClientID, request.clientID);
return Response{action()};
});
}

void _registerNotification(const std::string& name, const ParamFunc& action)
{
_jsonrpcServer->connect(name, [action](const auto& request) {
_jsonrpcServer->connect(name, [action, this](const auto& request) {
ScopedCurrentClient scope(this->_currentClientID, request.clientID);
action(request.message);
});
}

void _registerNotification(const std::string& name, const VoidFunc& action)
{
_jsonrpcServer->connect(name, [action] { action(); });
_jsonrpcServer->connect(name, [action, this](const auto& request) {
ScopedCurrentClient scope(this->_currentClientID, request.clientID);
action();
});
}

void processDelayedNotifies()
Expand Down

0 comments on commit c2421d0

Please sign in to comment.