Skip to content

Commit

Permalink
Take lock before accessing the value from map inside the handle
Browse files Browse the repository at this point in the history
  • Loading branch information
syeleti-msft committed Feb 6, 2025
1 parent 029fea8 commit 09526c0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions component/block_cache/block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,9 @@ func (bc *BlockCache) download(item *workItem) {

// Compare the ETAG value and fail download if blob has changed
if etag != "" {
item.handle.Lock()
etagVal, found := item.handle.GetValue("ETAG")
item.handle.Unlock()
if found && etagVal != etag {
log.Err("BlockCache::download : Blob has changed for %v=>%s (index %v, offset %v)", item.handle.ID, item.handle.Path, item.block.id, item.block.offset)
item.block.Failed()
Expand Down Expand Up @@ -1531,6 +1533,7 @@ return_safe:
}

// Stage the given number of blocks from this handle
// handle lock must be taken before calling this function
func (bc *BlockCache) commitBlocks(handle *handlemap.Handle) error {
log.Debug("BlockCache::commitBlocks : Staging blocks for %s", handle.Path)

Expand Down Expand Up @@ -1580,6 +1583,7 @@ func (bc *BlockCache) commitBlocks(handle *handlemap.Handle) error {
return err
}

// Lock was already acquired on the handle.
if newEtag != "" {
handle.SetValue("ETAG", newEtag)
}
Expand Down

0 comments on commit 09526c0

Please sign in to comment.