Skip to content

Commit 1277aab

Browse files
committed
Fix abort when the GC thread gets an exception
1 parent 0b606aa commit 1277aab

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/libstore/gc.cc

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -887,24 +887,32 @@ void LocalStore::autoGC(bool sync)
887887

888888
std::thread([promise{std::move(promise)}, this, avail, getAvail]() mutable {
889889

890-
/* Wake up any threads waiting for the auto-GC to finish. */
891-
Finally wakeup([&]() {
892-
auto state(_state.lock());
893-
state->gcRunning = false;
894-
state->lastGCCheck = std::chrono::steady_clock::now();
895-
promise.set_value();
896-
});
890+
try {
897891

898-
printInfo("running auto-GC to free %d bytes", settings.maxFree - avail);
892+
/* Wake up any threads waiting for the auto-GC to finish. */
893+
Finally wakeup([&]() {
894+
auto state(_state.lock());
895+
state->gcRunning = false;
896+
state->lastGCCheck = std::chrono::steady_clock::now();
897+
promise.set_value();
898+
});
899899

900-
GCOptions options;
901-
options.maxFreed = settings.maxFree - avail;
900+
printInfo("running auto-GC to free %d bytes", settings.maxFree - avail);
902901

903-
GCResults results;
902+
GCOptions options;
903+
options.maxFreed = settings.maxFree - avail;
904904

905-
collectGarbage(options, results);
905+
GCResults results;
906906

907-
_state.lock()->availAfterGC = getAvail();
907+
collectGarbage(options, results);
908+
909+
_state.lock()->availAfterGC = getAvail();
910+
911+
} catch (...) {
912+
// FIXME: we could propagate the exception to the
913+
// future, but we don't really care.
914+
ignoreException();
915+
}
908916

909917
}).detach();
910918
}

0 commit comments

Comments
 (0)