]> Sergey Matveev's repositories - btrtrc.git/blobdiff - torrent.go
Fix races around Reader and Torrent.Drop when Torrent is closed
[btrtrc.git] / torrent.go
index 7e6ec24cc2c8c76ac507e3e3adce34c3a5e14eec..6a75eff3452209df500d4bb01c8d1a4dd06d14ac 100644 (file)
@@ -153,7 +153,7 @@ type Torrent struct {
        // Torrent sources in use keyed by the source string.
        activeSources sync.Map
        sourcesLogger log.Logger
-       
+
        smartBanCache smartBanCache
 }
 
@@ -850,7 +850,10 @@ func (t *Torrent) numPiecesCompleted() (num pieceIndex) {
 }
 
 func (t *Torrent) close(wg *sync.WaitGroup) (err error) {
-       t.closed.Set()
+       if !t.closed.Set() {
+               err = errors.New("already closed")
+               return
+       }
        if t.storage != nil {
                wg.Add(1)
                go func() {