Commit 61ea2d81 authored by Elvin Sindrilaru's avatar Elvin Sindrilaru

MGM: Free slot taken by a proc command in the destructor to avoid any leak

parent d98aca0a
Pipeline #500100 canceled with stages
in 11 seconds
......@@ -51,7 +51,7 @@ IProcCommand::open(const char* path, const char* info,
int delay = 5;
if (!mExecRequest) {
if (HasSlot(mReqProto)) {
if (HasSlot()) {
LaunchJob();
mExecRequest = true;
} else {
......@@ -112,7 +112,6 @@ IProcCommand::open(const char* path, const char* info,
}
}
--mCmdsExecuting[mReqProto.command_case()];
return SFS_OK;
}
......@@ -199,10 +198,6 @@ IProcCommand::KillJob()
}
}
if (is_killed) {
--mCmdsExecuting[mReqProto.command_case()];
}
return is_killed;
}
......@@ -442,7 +437,7 @@ IProcCommand::IsOperationForbidden(const char* inpath)
// Check if there is still an available slot for the current type of command
//------------------------------------------------------------------------------
bool
IProcCommand::HasSlot(const eos::console::RequestProto& req_proto)
IProcCommand::HasSlot()
{
static std::atomic<bool> init {false};
......@@ -465,17 +460,19 @@ IProcCommand::HasSlot(const eos::console::RequestProto& req_proto)
}
uint64_t slot_limit {50};
auto it = mCmdsExecuting.find(req_proto.command_case());
auto it = mCmdsExecuting.find(mReqProto.command_case());
if (it == mCmdsExecuting.end()) {
// This should not happen unless you forgot to populate the map in the
// section above
mCmdsExecuting[req_proto.command_case()] = 1;
mCmdsExecuting[mReqProto.command_case()] = 1;
mHasSlot = true;
} else {
if (it->second >= slot_limit) {
return false;
} else {
++it->second;
mHasSlot = true;
}
}
......
......@@ -46,8 +46,9 @@ public:
//! Constructor
//----------------------------------------------------------------------------
IProcCommand():
mExecRequest(false), mReqProto(), mDoAsync(false), mForceKill(false),
mVid(), mComment(), stdOut(), stdErr(), stdJson(), retc(0), mTmpResp()
mHasSlot(false), mExecRequest(false), mReqProto(), mDoAsync(false),
mForceKill(false), mVid(), mComment(), stdOut(), stdErr(), stdJson(),
retc(0), mTmpResp()
{
mTimestamp = time(NULL);
}
......@@ -87,6 +88,10 @@ public:
}
unlink(ofstderrStreamFilename.c_str());
if (mHasSlot) {
--mCmdsExecuting[mReqProto.command_case()];
}
}
//----------------------------------------------------------------------------
......@@ -231,17 +236,17 @@ protected:
//! Check if there is still an available slot for the current type of command
//! in the queue served by the thread pool
//!
//! @param req_proto command request proto
//!
//! @return true if command can be queued, otherwise false
//----------------------------------------------------------------------------
static bool HasSlot(const eos::console::RequestProto& req_proto);
bool HasSlot();
static std::atomic_uint_least64_t uuid;
//! Map of command types to number of commands actually queued
static std::map<eos::console::RequestProto::CommandCase,
std::atomic<uint64_t>> mCmdsExecuting;
//! Indicate if current command has taken a slot in the queue
std::atomic<bool> mHasSlot;
bool mExecRequest; ///< Indicate if request is launched asynchronously
eos::console::RequestProto mReqProto; ///< Client request protobuf object
std::future<eos::console::ReplyProto> mFuture; ///< Response future
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment