8000 fix V8-context enter/exit pairs by dothebart · Pull Request #4879 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

fix V8-context enter/exit pairs #4879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2018
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
fix V8-context enter/exit pairs
  • Loading branch information
dothebart committed Mar 16, 2018
commit 8039b1ea6ac08dc949c9d58b7e594fd0134fadcc
29 changes: 28 additions & 1 deletion arangod/V8Server/V8DealerFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ V8Context* V8DealerFeature::addContext() {

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

bool V8DealerFeature::loadJavaScriptFileInContextNoLock(TRI_vocbase_t* vocbase,
std::string const& file, V8Context* context) {
TRI_ASSERT(vocbase != nullptr);
TRI_ASSERT(context != nullptr);

if (_stopping) {
return false;
}

if (!vocbase->use()) {
return false;
}

prepareLockedContext(vocbase, context, true);

try {
loadJavaScriptFileInternal(file, context, nullptr);
} catch (...) {
LOG_TOPIC(WARN, Logger::V8) << "caught exception while executing JavaScript file '" << file << "' in context #" << context->id();
throw;
}

return true;
}

void V8DealerFeature::loadJavaScriptFileInternal(std::string const& file, V8Context* context, VPackBuilder* builder) {
v8::HandleScope scope(context->_isolate);
auto localContext =
Expand All @@ -1368,6 +1393,8 @@ void V8DealerFeature::loadJavaScriptFileInternal(std::string const& file, V8Cont
}
}

localContext->Exit();

LOG_TOPIC(TRACE, arangodb::Logger::V8) << "loaded Javascript file '" << file << "' for V8 context #" << context->id();
}

Expand Down
1 change: 1 addition & 0 deletions arangod/V8Server/V8DealerFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class V8DealerFeature final : public application_features::ApplicationFeature {
void loadJavaScriptFileInternal(std::string const& file, V8Context* context,
VPackBuilder* builder);
bool loadJavaScriptFileInContext(TRI_vocbase_t*, std::string const& file, V8Context* context, VPackBuilder* builder);
bool loadJavaScriptFileInContextNoLock(TRI_vocbase_t*, std::string const& file, V8Context* context);
void prepareLockedContext(TRI_vocbase_t*, V8Context*, bool allowUseDatabase);
void exitContextInternal(V8Context*);
void cleanupLockedContext(V8Context*);
Expand Down
0