Skip to content

Commit 249746f

Browse files
committed
tx: add missing lock on meta page update
metalock is supposed to protect meta page, but it looks like the only place where we're modifying it is not protected in fact. Since page update is not atomic a concurrent reader (RO transaction) can get an inconsistent page. It's likely to fall back to the other one in this case, but still we better not allow this to happen. Signed-off-by: Roman Khimov <roman@nspcc.ru>
1 parent fde6016 commit 249746f

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

tx.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,13 @@ func (tx *Tx) writeMeta() error {
561561
tx.meta.Write(p)
562562

563563
// Write the meta page to file.
564+
tx.db.metalock.Lock()
564565
if _, err := tx.db.ops.writeAt(buf, int64(p.Id())*int64(tx.db.pageSize)); err != nil {
566+
tx.db.metalock.Unlock()
565567
lg.Errorf("writeAt failed, pgid: %d, pageSize: %d, error: %v", p.Id(), tx.db.pageSize, err)
566568
return err
567569
}
570+
tx.db.metalock.Unlock()
568571
if !tx.db.NoSync || common.IgnoreNoSync {
569572
// gofail: var beforeSyncMetaPage struct{}
570573
if err := fdatasync(tx.db); err != nil {

0 commit comments

Comments
 (0)