diff --git a/arangod/Aql/RestAqlHandler.cpp b/arangod/Aql/RestAqlHandler.cpp index 882ecb47de..01fd8d4c4b 100644 --- a/arangod/Aql/RestAqlHandler.cpp +++ b/arangod/Aql/RestAqlHandler.cpp @@ -32,6 +32,7 @@ #include "Aql/ExecutionBlock.h" #include "Basics/ConditionLocker.h" #include "Basics/StringUtils.h" +#include "Dispatcher/DispatcherThread.h" #include "HttpServer/HttpServer.h" #include "HttpServer/HttpHandlerFactory.h" #include "Rest/HttpRequest.h" @@ -694,16 +695,28 @@ void RestAqlHandler::handleUseQuery (std::string const& operation, Json answerBody(Json::Object, 3); if (operation == "lock") { + // Mark current thread as potentially blocking: + auto currentThread = triagens::rest::DispatcherThread::currentDispatcherThread; + + if (currentThread != nullptr) { + triagens::rest::DispatcherThread::currentDispatcherThread->blockThread(); + } int res = TRI_ERROR_INTERNAL; try { res = query->trx()->lockCollections(); } catch (...) { LOG_ERROR("lock lead to an exception"); + if (currentThread != nullptr) { + triagens::rest::DispatcherThread::currentDispatcherThread->unblockThread(); + } generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_HTTP_SERVER_ERROR, "lock lead to an exception"); return; } + if (currentThread != nullptr) { + triagens::rest::DispatcherThread::currentDispatcherThread->unblockThread(); + } answerBody("error", res == TRI_ERROR_NO_ERROR ? Json(false) : Json(true)) ("code", Json(static_cast(res))); } diff --git a/arangod/V8Server/ApplicationV8.cpp b/arangod/V8Server/ApplicationV8.cpp index 3d5a91837c..14232e68ed 100644 --- a/arangod/V8Server/ApplicationV8.cpp +++ b/arangod/V8Server/ApplicationV8.cpp @@ -47,6 +47,7 @@ #include "Basics/tri-strings.h" #include "Cluster/ServerState.h" #include "Cluster/v8-cluster.h" +#include "Dispatcher/DispatcherThread.h" #include "Dispatcher/ApplicationDispatcher.h" #include "Rest/HttpRequest.h" #include "Scheduler/ApplicationScheduler.h" @@ -358,7 +359,15 @@ ApplicationV8::V8Context* ApplicationV8::enterContext (std::string const& name, while (_freeContexts[name].empty() && ! _stopping) { LOG_DEBUG("waiting for unused V8 context"); + auto currentThread = triagens::rest::DispatcherThread::currentDispatcherThread; + + if (currentThread != nullptr) { + triagens::rest::DispatcherThread::currentDispatcherThread->blockThread(); + } guard.wait(); + if (currentThread != nullptr) { + triagens::rest::DispatcherThread::currentDispatcherThread->unblockThread(); + } } // in case we are in the shutdown phase, do not enter a context!