fix crash on close torrent and clean pieces

This commit is contained in:
YouROK
2021-08-16 09:51:17 +03:00
parent 85d53c58e7
commit 8d25a5b30b
2 changed files with 12 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ type Cache struct {
muReaders sync.Mutex
isRemove bool
isClosed bool
muRemove sync.Mutex
torrent *torrent.Torrent
}
@@ -89,6 +90,8 @@ func (c *Cache) Piece(m metainfo.Piece) storage.PieceImpl {
func (c *Cache) Close() error {
log.TLogln("Close cache for:", c.hash)
c.isClosed = true
delete(c.storage.caches, c.hash)
if settings.BTsets.RemoveCacheOnDrop {
@@ -114,8 +117,10 @@ func (c *Cache) Close() error {
}
func (c *Cache) removePiece(piece *Piece) {
if !c.isClosed {
piece.Release()
}
}
func (c *Cache) AdjustRA(readahead int64) {
if settings.BTsets.CacheSize == 0 {
@@ -177,7 +182,7 @@ func (c *Cache) GetState() *state.CacheState {
}
func (c *Cache) cleanPieces() {
if c.isRemove {
if c.isRemove || c.isClosed {
return
}
c.muRemove.Lock()

View File

@@ -76,7 +76,9 @@ func (p *Piece) Release() {
p.dPiece.Release()
}
if !p.cache.isClosed {
p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone)
// fix remove pieces hash
p.cache.torrent.Piece(p.Id).UpdateCompletion()
}
}