Skip to content

Commit 2a836bb

Browse files
core/rawdb: fix data race between Retrieve and Close (#20919)
* core/rawdb: fixed data race between retrieve and close closes #20420 * core/rawdb: use non-atomic load while holding mutex
1 parent eb2fd82 commit 2a836bb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/rawdb/freezer_table.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,20 +541,22 @@ func (t *freezerTable) getBounds(item uint64) (uint32, uint32, uint32, error) {
541541
// Retrieve looks up the data offset of an item with the given number and retrieves
542542
// the raw binary blob from the data file.
543543
func (t *freezerTable) Retrieve(item uint64) ([]byte, error) {
544+
t.lock.RLock()
544545
// Ensure the table and the item is accessible
545546
if t.index == nil || t.head == nil {
547+
t.lock.RUnlock()
546548
return nil, errClosed
547549
}
548550
if atomic.LoadUint64(&t.items) <= item {
551+
t.lock.RUnlock()
549552
return nil, errOutOfBounds
550553
}
551554
// Ensure the item was not deleted from the tail either
552-
offset := atomic.LoadUint32(&t.itemOffset)
553-
if uint64(offset) > item {
555+
if uint64(t.itemOffset) > item {
556+
t.lock.RUnlock()
554557
return nil, errOutOfBounds
555558
}
556-
t.lock.RLock()
557-
startOffset, endOffset, filenum, err := t.getBounds(item - uint64(offset))
559+
startOffset, endOffset, filenum, err := t.getBounds(item - uint64(t.itemOffset))
558560
if err != nil {
559561
t.lock.RUnlock()
560562
return nil, err

0 commit comments

Comments
 (0)