From 0ffbe628e376ee133075772ee2d464ef32bf7da0 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 22 Nov 2018 13:48:07 +0100 Subject: [PATCH] Fix: Two concurrent transactions are a dead-lock Signed-off-by: Knut Ahlers --- backend.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend.go b/backend.go index 345b353..2e455f0 100644 --- a/backend.go +++ b/backend.go @@ -171,12 +171,14 @@ func (b backend) getFeedKey(feedName string) (crypto.PublicKey, error) { func (b backend) getFeedLastUpdate(feedName string) (time.Time, error) { t := time.Now() // Fallback: Assume last update was now - err := b.db.Update(func(tx *bolt.Tx) error { - b, err := tx.CreateBucketIfNotExists(dateBucket) - if err != nil { - return err + err := b.db.View(func(tx *bolt.Tx) error { + b := tx.Bucket(dateBucket) + if b == nil { + return nil // The bucket is not yet there, just use current time } + var err error + k := []byte(feedName) v := b.Get(k)