8000 Bug fix/fix collection leak by jsteemann · Pull Request #2986 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Bug fix/fix collection leak #2986

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 3 commits into from
Aug 8, 2017
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
17 changes: 16 additions & 1 deletion arangod/V8Server/v8-collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3045,15 +3045,28 @@ static void JS_CollectionsVocbase(
}

std::vector<LogicalCollection*> colls;

// clean memory
std::function<void()> cleanup;

// if we are a coordinator, we need to fetch the collection info from the
// agency
if (ServerState::instance()->isCoordinator()) {
cleanup = [&colls]() {
for (auto& it : colls) {
if (it != nullptr) {
delete it;
}
}
};
colls = GetCollectionsCluster(vocbase);
} else {
colls = vocbase->collections(false);
}

// make sure memory is cleaned up
TRI_DEFER(cleanup());

std::sort(colls.begin(), colls.end(), [](LogicalCollection* lhs, LogicalCollection* rhs) -> bool {
return StringUtils::tolower(lhs->name()) < StringUtils::tolower(rhs->name());
});
Expand All @@ -3066,7 +3079,7 @@ static void JS_CollectionsVocbase(
size_t const n = colls.size();
size_t x = 0;
for (size_t i = 0; i < n; ++i) {
auto collection = colls[i];
auto& collection = colls[i];

if (auth->isActive() && ExecContext::CURRENT != nullptr) {
AuthLevel level = auth->canUseCollection(ExecContext::CURRENT->user(),
Expand All @@ -3081,6 +3094,8 @@ static void JS_CollectionsVocbase(
error = true;
break;
}
// avoid duplicate deletion
collection = nullptr;
result->Set(static_cast<uint32_t>(x++), c);
}

Expand Down
27 changes: 18 additions & 9 deletions arangosh/Shell/V8ClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static v8::Handle<v8::Value> WrapV8ClientConnection(

static void ClientConnection_ConstructorCallback(
v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(args.Data());
Expand 8000 Down Expand Up @@ -350,6 +350,7 @@ static void ClientConnection_ConstructorCallback(
}

TRI_V8_RETURN(WrapV8ClientConnection(isolate, v8connection.release()));
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -504,7 +505,7 @@ static void ClientConnection_httpGetRaw(

static void ClientConnection_httpHeadAny(
v8::FunctionCallbackInfo<v8::Value> const& args, bool raw) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

// get the connection
Expand All @@ -530,6 +531,7 @@ static void ClientConnection_httpHeadAny(
}

TRI_V8_RETURN(v8connection->headData(isolate, *url, headerFields, raw));
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -556,7 +558,7 @@ static void ClientConnection_httpHeadRaw(

static void ClientConnection_httpDeleteAny(
v8::FunctionCallbackInfo<v8::Value> const& args, bool raw) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

// get the connection
Expand Down Expand Up @@ -588,6 +590,7 @@ static 8000 void ClientConnection_httpDeleteAny(
}

TRI_V8_RETURN(v8connection->deleteData(isolate, *url, headerFields, raw, std::string()));
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -614,7 +617,7 @@ static void ClientConnection_httpDeleteRaw(

static void ClientConnection_httpOptionsAny(
v8::FunctionCallbackInfo<v8::Value> const& args, bool raw) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

// get the connection
Expand Down Expand Up @@ -643,6 +646,7 @@ static void ClientConnection_httpOptionsAny(

TRI_V8_RETURN(
v8connection->optionsData(isolate, *url, *body, headerFields, raw));
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -669,7 +673,7 @@ static void ClientConnection_httpOptionsRaw(

static void ClientConnection_httpPostAny(
v8::FunctionCallbackInfo<v8::Value> const& args, bool raw) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

// get the connection
Expand Down Expand Up @@ -698,6 +702,7 @@ static void ClientConnection_httpPostAny(

TRI_V8_RETURN(
v8connection->postData(isolate, *url, *body, headerFields, raw));
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -724,7 +729,7 @@ static void ClientConnection_httpPostRaw(

static void ClientConnection_httpPutAny(
v8::FunctionCallbackInfo<v8::Value> const& args, bool raw) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

// get the connection
Expand Down Expand Up @@ -752,6 +757,7 @@ static void ClientConnection_httpPutAny(
}

TRI_V8_RETURN(v8connection->putData(isolate, *url, *body, headerFields, raw));
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -778,7 +784,7 @@ static void ClientConnection_httpPutRaw(

static void ClientConnection_httpPatchAny(
v8::FunctionCallbackInfo<v8::Value> const& args, bool raw) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

// get the connection
Expand Down Expand Up @@ -807,6 +813,7 @@ static void ClientConnection_httpPatchAny(

TRI_V8_RETURN(
v8connection->patchData(isolate, *url, *body, headerFields, raw));
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -833,7 +840,7 @@ static void ClientConnection_httpPatchRaw(

static void ClientConnection_httpSendFile(
v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

// get the connection
Expand Down Expand Up @@ -879,6 +886,7 @@ static void ClientConnection_httpSendFile(
}

TRI_V8_RETURN(result);
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -887,7 +895,7 @@ static void ClientConnection_httpSendFile(

static void ClientConnection_getEndpoint(
v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Isolate* isolate = args.GetIsolate();
TRI_V8_TRY_CATCH_BEGIN(isolate)
v8::HandleScope scope(isolate);

// get the connection
Expand All @@ -907,6 +915,7 @@ static void ClientConnection_getEndpoint(
}

TRI_V8_RETURN_STD_STRING(client->endpoint());
TRI_V8_TRY_CATCH_END
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 10 additions & 5 deletions arangosh/Shell/V8ShellFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ void V8ShellFeature::unprepare() {

v8::Context::Scope context_scope{context};

// remove any objects stored in _last global value
context->Global()->Delete(TRI_V8_ASCII_STRING2(_isolate, "_last"));
// clear globals to free memory
auto globals = _isolate->GetCurrentContext()->Global();
v8::Handle<v8::Array> names = globals->GetOwnPropertyNames();
uint32_t const n = names->Length();
for (uint32_t i = 0; i < n; ++i) {
globals->Delete(names->Get(i));
}

TRI_RunGarbageCollectionV8(_isolate, 2500.0);
}
Expand All @@ -178,7 +183,7 @@ void V8ShellFeature::unprepare() {

_context.Reset();
}

_isolate->Dispose();

// turn on memory allocation failures again
Expand Down Expand Up @@ -304,8 +309,8 @@ V8ClientConnection* V8ShellFeature::setup(

int V8ShellFeature::runShell(std::vector<std::string> const& positionals) {
v8::Locker locker{_isolate};

v8::Isolate::Scope isolate_scope(_isolate);

v8::HandleScope handle_scope(_isolate);

v8::Local<v8::Context> context =
Expand Down Expand Up @@ -434,7 +439,7 @@ int V8ShellFeature::runShell(std::vector<std::string> const& positionals) {
V8PlatformFeature::resetOutOfMemory(_isolate);
}
}

if (!_console->quiet()) {
_console->printLine("");
_console->printByeBye();
Expand Down
0