Skip to content

Commit

Permalink
close storage after other components
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed Aug 7, 2024
1 parent 43e17e4 commit 40a6dda
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,27 @@ func (t *Torrent) close(wg *sync.WaitGroup) (err error) {
f()
}

func() {
t.mu.Lock()
defer t.mu.Unlock()

t.iterPeers(func(p *Peer) {
p.close(false)
}, false)
if t.storage != nil {
t.deletePieceRequestOrder()
}
t.assertAllPiecesRelativeAvailabilityZero(false)
t.pex.Reset()
t.cl.event.Broadcast()
t.pieceStateChanges.Close()
t.updateWantPeersEvent(false)
if t.hashResults != nil {
close(t.hashResults)
t.hashResults = nil
}
}()

if t.storage != nil {
closed := make(chan struct{})
defer func() { closed <- struct{}{} }()
Expand All @@ -1093,24 +1114,6 @@ func (t *Torrent) close(wg *sync.WaitGroup) (err error) {
}()
}

t.mu.Lock()
defer t.mu.Unlock()

t.iterPeers(func(p *Peer) {
p.close(false)
}, false)
if t.storage != nil {
t.deletePieceRequestOrder()
}
t.assertAllPiecesRelativeAvailabilityZero(false)
t.pex.Reset()
t.cl.event.Broadcast()
t.pieceStateChanges.Close()
t.updateWantPeersEvent(false)
if t.hashResults != nil {
close(t.hashResults)
t.hashResults = nil
}
return
}

Expand Down

0 comments on commit 40a6dda

Please sign in to comment.