about summary refs log tree commit diff
path: root/src/libstore/gc.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-09-06T09·37+0200
committerEelco Dolstra <edolstra@gmail.com>2017-09-06T09·37+0200
commit1277aab219c83beae856024eea6e868677f7523b (patch)
tree37c4f01a96f4f9238e2b73f7be83822453816cb8 /src/libstore/gc.cc
parent0b606aad46e1d96da36d4831df63ad90f11d21c3 (diff)
Fix abort when the GC thread gets an exception
Diffstat (limited to 'src/libstore/gc.cc')
-rw-r--r--src/libstore/gc.cc34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index cf95f7f450bd..45f28c328a5e 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -887,24 +887,32 @@ void LocalStore::autoGC(bool sync)
 
         std::thread([promise{std::move(promise)}, this, avail, getAvail]() mutable {
 
-            /* Wake up any threads waiting for the auto-GC to finish. */
-            Finally wakeup([&]() {
-                auto state(_state.lock());
-                state->gcRunning = false;
-                state->lastGCCheck = std::chrono::steady_clock::now();
-                promise.set_value();
-            });
+            try {
 
-            printInfo("running auto-GC to free %d bytes", settings.maxFree - avail);
+                /* Wake up any threads waiting for the auto-GC to finish. */
+                Finally wakeup([&]() {
+                    auto state(_state.lock());
+                    state->gcRunning = false;
+                    state->lastGCCheck = std::chrono::steady_clock::now();
+                    promise.set_value();
+                });
 
-            GCOptions options;
-            options.maxFreed = settings.maxFree - avail;
+                printInfo("running auto-GC to free %d bytes", settings.maxFree - avail);
 
-            GCResults results;
+                GCOptions options;
+                options.maxFreed = settings.maxFree - avail;
 
-            collectGarbage(options, results);
+                GCResults results;
 
-            _state.lock()->availAfterGC = getAvail();
+                collectGarbage(options, results);
+
+                _state.lock()->availAfterGC = getAvail();
+
+            } catch (...) {
+                // FIXME: we could propagate the exception to the
+                // future, but we don't really care.
+                ignoreException();
+            }
 
         }).detach();
     }