From 925e15b8c467f8555dd08b9d4ce3ab9a513a1e1a Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Wed, 25 Nov 2020 17:59:19 +0530 Subject: [PATCH] Fix race condition in L0StallMs variable (#1605) This fixes two issues - Atomic variable was not being accessed correctly - Atomic variable should be the first member of the struct to ensure proper alignment. Failure to do so will cause a segmentation fault. Fixes DGRAPH-2773 --- db.go | 2 +- levels.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db.go b/db.go index eb8a3b85b..3065837f4 100644 --- a/db.go +++ b/db.go @@ -477,7 +477,7 @@ func (db *DB) IsClosed() bool { func (db *DB) close() (err error) { db.opt.Debugf("Closing database") - db.opt.Infof("Lifetime L0 stalled for: %s\n", time.Duration(db.lc.l0stallsMs)) + db.opt.Infof("Lifetime L0 stalled for: %s\n", time.Duration(atomic.LoadInt64(&db.lc.l0stallsMs))) atomic.StoreInt32(&db.blockWrites, 1) diff --git a/levels.go b/levels.go index 0b3950817..49f7ccbe8 100644 --- a/levels.go +++ b/levels.go @@ -41,13 +41,13 @@ import ( type levelsController struct { nextFileID uint64 // Atomic + l0stallsMs int64 // Atomic // The following are initialized once and const. levels []*levelHandler kv *DB - cstatus compactStatus - l0stallsMs int64 + cstatus compactStatus } // revertToManifest checks that all necessary table files exist and removes all table files not