summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_where.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2019-01-03 16:38:26 -0500
committerJason Carey <jcarey@argv.me>2019-02-10 12:23:19 -0500
commit21b5477520744ca02e1574160caa31e0633849dd (patch)
tree36f351a91a195a633c9cc495f6249057497249ff /src/mongo/db/matcher/expression_where.cpp
parentc922cb18516981ceca59993331296d102f4e01fb (diff)
downloadmongo-21b5477520744ca02e1574160caa31e0633849dd.tar.gz
SERVER-39183 honor socket disconnect in $where
Diffstat (limited to 'src/mongo/db/matcher/expression_where.cpp')
-rw-r--r--src/mongo/db/matcher/expression_where.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_where.cpp b/src/mongo/db/matcher/expression_where.cpp
index c6633bc3802..7d1f261370f 100644
--- a/src/mongo/db/matcher/expression_where.cpp
+++ b/src/mongo/db/matcher/expression_where.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/namespace_string.h"
#include "mongo/scripting/engine.h"
#include "mongo/stdx/memory.h"
+#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -67,6 +68,8 @@ WhereMatchExpression::WhereMatchExpression(OperationContext* opCtx,
AuthorizationSession::get(Client::getCurrent())->getAuthenticatedUserNamesToken();
_scope = getGlobalScriptEngine()->getPooledScope(_opCtx, _dbName, "where" + userToken);
+ const auto guard = makeGuard([&] { _scope->unregisterOperation(); });
+
_func = _scope->createFunction(getCode().c_str());
uassert(ErrorCodes::BadValue, "$where compile error", _func);
@@ -76,6 +79,9 @@ bool WhereMatchExpression::matches(const MatchableDocument* doc, MatchDetails* d
uassert(28692, "$where compile error", _func);
BSONObj obj = doc->toBSON();
+ _scope->registerOperation(Client::getCurrent()->getOperationContext());
+ const auto guard = makeGuard([&] { _scope->unregisterOperation(); });
+
if (!getScope().isEmpty()) {
_scope->init(&getScope());
}