Skip to content

Commit

Permalink
ffldb: close block files
Browse files Browse the repository at this point in the history
On methods readBlock and readBlockRegion, the opened files were never
closed which resulted in errors when attempting to delete these files on
pruning on windows.  Properly closing the files avoids this error.
  • Loading branch information
kcalvinalvin committed Jul 1, 2024
1 parent d881c68 commit f9d7cb3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions database/ffldb/blockio.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ func (s *blockStore) readBlock(hash *chainhash.Hash, loc blockLocation) ([]byte,
serializedData := make([]byte, loc.blockLen)
n, err := blockFile.file.ReadAt(serializedData, int64(loc.fileOffset))
blockFile.RUnlock()
blockFile.file.Close()
if err != nil {
str := fmt.Sprintf("failed to read block %s from file %d, "+
"offset %d: %v", hash, loc.blockFileNum, loc.fileOffset,
Expand Down Expand Up @@ -584,6 +585,7 @@ func (s *blockStore) readBlockRegion(loc blockLocation, offset, numBytes uint32)
serializedData := make([]byte, numBytes)
_, err = blockFile.file.ReadAt(serializedData, int64(readOffset))
blockFile.RUnlock()
blockFile.file.Close()
if err != nil {
str := fmt.Sprintf("failed to read region from block file %d, "+
"offset %d, len %d: %v", loc.blockFileNum, readOffset,
Expand Down

0 comments on commit f9d7cb3

Please sign in to comment.