From 53942b741ae51fe28c2f86376c03e3d33118841a Mon Sep 17 00:00:00 2001 From: Aaron Korte Date: Thu, 24 Oct 2019 00:38:41 +0200 Subject: [PATCH] fix(api): increment stack identifier atomically (#3290) --- api/bolt/internal/db.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/bolt/internal/db.go b/api/bolt/internal/db.go index 8cbb1d2d0..9689fa691 100644 --- a/api/bolt/internal/db.go +++ b/api/bolt/internal/db.go @@ -82,13 +82,15 @@ func DeleteObject(db *bolt.DB, bucketName string, key []byte) error { func GetNextIdentifier(db *bolt.DB, bucketName string) int { var identifier int - db.View(func(tx *bolt.Tx) error { + db.Update(func(tx *bolt.Tx) error { bucket := tx.Bucket([]byte(bucketName)) - id := bucket.Sequence() + id, err := bucket.NextSequence() + if err != nil { + return err + } identifier = int(id) return nil }) - identifier++ return identifier }