[geary/mjog/579-logging-deadlock] Fix deadlock when finalising log records generates more logging
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/579-logging-deadlock] Fix deadlock when finalising log records generates more logging
- Date: Sat, 28 Sep 2019 12:26:51 +0000 (UTC)
commit 6d74f4e50dd776774cda193565a7779eb501ef99
Author: Michael Gratton <mike vee net>
Date: Sat Sep 28 22:25:36 2019 +1000
Fix deadlock when finalising log records generates more logging
Make sure records are finalised outside the lock.
Should fix #579
src/engine/api/geary-logging.vala | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/src/engine/api/geary-logging.vala b/src/engine/api/geary-logging.vala
index faee162b..c633910b 100644
--- a/src/engine/api/geary-logging.vala
+++ b/src/engine/api/geary-logging.vala
@@ -369,11 +369,27 @@ public void init() {
public void clear() {
record_lock.lock();
+ // Keep the old first record around for two reasons. First, so we
+ // don't cause potentially thousands of record to be finalised
+ // under the lock, and hence causing a deadlock with
+ // default_log_writer if the finalisation causes more logging to
+ // be generated. Second, so finalising doesn't cause an extremely
+ // deep stack as the first record is finalised, causing the second
+ // to be finalised, causing the third..., and so on.
+ Record? old_first = first_record;
+
first_record = null;
last_record = null;
log_length = 0;
-
+
record_lock.unlock();
+
+ while (old_first != null) {
+ // Per the second reason above, by manually clearing each log
+ // record here in a loop, finalisation of each is an iterative
+ // process, not recursive.
+ old_first = old_first.next;
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]