Skip to content
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
20 changes: 20 additions & 0 deletions lib/remote/consolehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ static void ScriptFrameCleanupHandler()
std::vector<String> cleanup_keys;

for (auto& kv : l_ApiScriptFrames) {
std::unique_lock frameLock(kv.second->Mutex, std::try_to_lock);
if (!frameLock) {
// If the frame is locked, it's in use, don't expire it this time.
continue;
}

if (kv.second->Seen < Utility::GetTime() - 1800)
cleanup_keys.push_back(kv.first);
}
Expand Down Expand Up @@ -126,6 +132,13 @@ bool ConsoleHandler::ExecuteScriptHelper(boost::beast::http::request<boost::beas
EnsureFrameCleanupTimer();

auto lsf = GetOrCreateScriptFrame(session);

std::unique_lock frameLock(lsf->Mutex, std::try_to_lock);
if (!frameLock) {
HttpUtility::SendJsonError(response, params, 409, "Session is currently in use by another request.");
return true;
}

lsf->Seen = Utility::GetTime();

if (!lsf->Locals)
Expand Down Expand Up @@ -201,6 +214,13 @@ bool ConsoleHandler::AutocompleteScriptHelper(boost::beast::http::request<boost:
EnsureFrameCleanupTimer();

auto lsf = GetOrCreateScriptFrame(session);

std::unique_lock frameLock(lsf->Mutex, std::try_to_lock);
if (!frameLock) {
HttpUtility::SendJsonError(response, params, 409, "Session is currently in use by another request.");
return true;
}

lsf->Seen = Utility::GetTime();

if (!lsf->Locals)
Expand Down
2 changes: 2 additions & 0 deletions lib/remote/consolehandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

#include "remote/httphandler.hpp"
#include "base/scriptframe.hpp"
#include <mutex>

namespace icinga
{

struct ApiScriptFrame
{
std::mutex Mutex;
double Seen{0};
int NextLine{1};
std::map<String, String> Lines;
Expand Down
Loading