Fix racy Torrent.wantConns check when adding connections

This commit is contained in:
Matt Joiner 2018-06-26 20:47:21 +10:00
parent 6212973011
commit 8255194c64
1 changed files with 3 additions and 3 deletions

View File

@ -1524,11 +1524,11 @@ func (t *Torrent) addConnection(c *connection) (err error) {
return errors.New("existing connection preferred")
}
}
if !t.wantConns() {
return errors.New("don't want conns")
}
if len(t.conns) >= t.maxEstablishedConns {
c := t.worstBadConn()
if c == nil {
return errors.New("don't want conns")
}
if t.cl.config.Debug && missinggo.CryHeard() {
log.Printf("%s: dropping connection to make room for new one:\n %v", t, c)
}