Skip to content

Commit

Permalink
Don't allow to modify/create/delete an object concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Mar 11, 2024
1 parent 3d3ad2b commit 4a43f0e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/remote/createobjecthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ bool CreateObjectHandler::HandleRequest(
return true;
}

// Lock the object name of the given type to prevent from being created concurrently.
ObjectNameMutex objectNameLock(type, name);

if (!ConfigObjectUtility::CreateObject(type, name, config, errors, diagnosticInformation)) {
result1->Set("errors", errors);
result1->Set("code", 500);
Expand Down
3 changes: 3 additions & 0 deletions lib/remote/deleteobjecthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ bool DeleteObjectHandler::HandleRequest(
Array::Ptr errors = new Array();
Array::Ptr diagnosticInformation = new Array();

// Lock the object name of the given type to prevent from being modified/deleted concurrently.
ObjectNameMutex objectNameLock(type, obj->GetName());

if (!ConfigObjectUtility::DeleteObject(obj, cascade, errors, diagnosticInformation)) {
code = 500;
status = "Object could not be deleted.";
Expand Down
3 changes: 3 additions & 0 deletions lib/remote/modifyobjecthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ bool ModifyObjectHandler::HandleRequest(

String key;

// Lock the object name of the given type to prevent from being modified/deleted concurrently.
ObjectNameMutex objectNameLock(type, obj->GetName());

try {
if (restoreAttrs) {
ObjectLock oLock (restoreAttrs);
Expand Down

0 comments on commit 4a43f0e

Please sign in to comment.