8000 fix V8-context enter/exit pairs (#4879) · Sandychuang/arangodb@5c70062 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c70062

Browse files
dothebartjsteemann
authored andcommitted
fix V8-context enter/exit pairs (arangodb#4879)
1 parent 7b99fd0 commit 5c70062

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

arangod/V8Server/V8DealerFeature.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ V8Context* V8DealerFeature::addContext() {
322322

323323
// no other thread can use the context when we are here, as the
324324
// context has not been added to the global list of contexts yet
325-
loadJavaScriptFileInContext(database->systemDatabase(), "server/initialize.js", context, nullptr);
325+
loadJavaScriptFileInContextNoLock(database->systemDatabase(), "server/initialize.js", context);
326326
return context;
327327
} catch (...) {
328328
delete context;
@@ -1342,6 +1342,31 @@ bool V8DealerFeature::loadJavaScriptFileInContext(TRI_vocbase_t* vocbase,
13421342
return true;
13431343
}
13441344

1345+
bool V8DealerFeature::loadJavaScriptFileInContextNoLock(TRI_vocbase_t* vocbase,
1346+
std::string const& file, V8Context* context) {
1347+
TRI_ASSERT(vocbase != nullptr);
1348+
TRI_ASSERT(context != nullptr);
1349+
1350+
if (_stopping) {
1351+
return false;
1352+
}
1353+
1354+
if (!vocbase->use()) {
1355+
return false;
1356+
}
1357+
1358+
prepareLockedContext(vocbase, context, true);
1359+
1360+
try {
1361+
loadJavaScriptFileInternal(file, context, nullptr);
1362+
} catch (...) {
1363+
LOG_TOPIC(WARN, Logger::V8) << "caught exception while executing JavaScript file '" << file << "' in context #" << context->id();
1364+
throw;
1365+
}
1366+
1367+
return true;
1368+
}
1369+
13451370
void V8DealerFeature::loadJavaScriptFileInternal(std::string const& file, V8Context* context, VPackBuilder* builder) {
13461371
v8::HandleScope scope(context->_isolate);
13471372
auto localContext =
@@ -1368,6 +1393,8 @@ void V8DealerFeature::loadJavaScriptFileInternal(std::string const& file, V8Cont
13681393
}
13691394
}
13701395

1396+
localContext->Exit();
1397+
13711398
LOG_TOPIC(TRACE, arangodb::Logger::V8) << "loaded Javascript file '" << file << "' for V8 context #" << context->id();
13721399
}
13731400

arangod/V8Server/V8DealerFeature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class V8DealerFeature final : public application_features::ApplicationFeature {
133133
void loadJavaScriptFileInternal(std::string const& file, V8Context* context,
134134
VPackBuilder* builder);
135135
bool loadJavaScriptFileInContext(TRI_vocbase_t*, std::string const& file, V8Context* context, VPackBuilder* builder);
136+
bool loadJavaScriptFileInContextNoLock(TRI_vocbase_t*, std::string const& file, V8Context* context);
136137
void prepareLockedContext(TRI_vocbase_t*, V8Context*, bool allowUseDatabase);
137138
void exitContextInternal(V8Context*);
138139
void cleanupLockedContext(V8Context*);

0 commit comments

Comments
 (0)
0