8000 Fix potential memleak in Pregel conductor garbage collection. (#14466) · arangodb/arangodb@254986b · GitHub
[go: up one dir, main page]

Skip to content

Commit 254986b

Browse files
jsteemannmaierlars
authored and
maierlars
committed
Fix potential memleak in Pregel conductor garbage collection. (#14466)
1 parent b81e1ae commit 254986b

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
devel
22
-----
33

4+
* Fix potential memleak in Pregel conductor garbage collection.
5+
46
* Added a retry loop for arangorestore during the initial connection phase. The
57
number of retries defaults to 3 and can be configured using
68
--initial-connect-retries.

arangod/Pregel/PregelFeature.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ void PregelFeature::scheduleGarbageCollection() {
261261
"No thread available to queue Pregel garbage collection");
262262
}
263263

264+
MUTEX_LOCKER(guard, _mutex);
264265
_gcHandle = std::move(handle);
265266
}
266267

@@ -278,9 +279,10 @@ void PregelFeature::start() {
278279

279280
void PregelFeature::beginShutdown() {
280281
TRI_ASSERT(isStopping());
281-
_gcHandle.reset();
282282

283283
MUTEX_LOCKER(guard, _mutex);
284+
_gcHandle.reset();
285+
284286
// cancel all conductors and workers
285287
for (auto& it : _conductors) {
286288
it.second.conductor->cancel();
@@ -291,6 +293,8 @@ void PregelFeature::beginShutdown() {
291293
}
292294

293295
void PregelFeature::unprepare() {
296+
garbageCollectConductors();
297+
294298
MUTEX_LOCKER(guard, _mutex);
295299
decltype(_conductors) cs = std::move(_conductors);
296300
decltype(_workers) ws = std::move(_workers);
@@ -336,6 +340,7 @@ void PregelFeature::garbageCollectConductors() try {
336340
if (it->second.conductor->canBeGarbageCollected()) {
337341
uint64_t executionNumber = it->first;
338342

343+
it->second.conductor->cancel();
339344
it = _conductors.erase(it);
340345

341346
_workers.erase(executionNumber);

arangod/Scheduler/Scheduler.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,27 @@ class Scheduler {
154154
[[nodiscard]] virtual bool queueItem(RequestLane lane, std::unique_ptr<WorkItemBase> item) = 0;
155155

156156
public:
157-
// delay Future returns a future that will be fulfilled after the given duration
158-
// requires scheduler
159-
// If d is zero, the future is fulfilled immediately. Throws a logic error
160-
// if delay was cancelled.
161-
futures::Future<futures::Unit> delay(clock::duration d) {
162-
if (d == clock::duration::zero()) {
163-
return futures::makeFuture();
164-
}
157+
// delay Future returns a future that will be fulfilled after the given duration
158+
// requires scheduler
159+
// If d is zero, the future is fulfilled immediately. Throws a logic error
160+
// if delay was cancelled.
161+
futures::Future<futures::Unit> delay(clock::duration d) {
162+
if (d == clock::duration::zero()) {
163+
return futures::makeFuture();
164+
}
165165

166-
futures::Promise<bool> p;
167-
futures::Future<bool> f = p.getFuture();
166+
futures::Promise<bool> p;
167+
futures::Future<bool> f = p.getFuture();
168168

169-
auto item = queueDelay(RequestLane::DELAYED_FUTURE, d,
170-
[pr = std::move(p)](bool cancelled) mutable { pr.setValue(cancelled); });
169+
auto item = queueDelay(RequestLane::DELAYED_FUTURE, d,
170+
[pr = std::move(p)](bool cancelled) mutable { pr.setValue(cancelled); });
171171

172-
return std::move(f).thenValue([item = std::move(item)](bool cancelled) {
173-
if (cancelled) {
174-
throw std::logic_error("delay was cancelled");
175-
}
176-
});
177-
}
172+
return std::move(f).thenValue([item = std::move(item)](bool cancelled) {
173+
if (cancelled) {
174+
throw std::logic_error("delay was cancelled");
175+
}
176+
});
177+
}
178178

179179
// ---------------------------------------------------------------------------
180180
// CronThread and delayed tasks

0 commit comments

Comments
 (0)
0