Improve some lock handling under panics

This commit is contained in:
Matt Joiner 2021-05-09 17:31:45 +10:00
parent 627b75c8b4
commit 4ab20f60b6
2 changed files with 6 additions and 4 deletions

2
t.go
View File

@ -85,8 +85,8 @@ func (t *Torrent) PieceBytesMissing(piece int) int64 {
// or connected peers.
func (t *Torrent) Drop() {
t.cl.lock()
defer t.cl.unlock()
t.cl.dropTorrent(t.infoHash)
t.cl.unlock()
}
// Number of bytes of the entire torrent we have completed. This is the sum of

View File

@ -741,9 +741,11 @@ func (t *Torrent) close() (err error) {
t.closed.Set()
t.tickleReaders()
if t.storage != nil {
t.storageLock.Lock()
t.storage.Close()
t.storageLock.Unlock()
func() {
t.storageLock.Lock()
defer t.storageLock.Unlock()
t.storage.Close()
}()
}
t.iterPeers(func(p *Peer) {
p.close()