Defer closing connections to prevent leaking them
This commit is contained in:
parent
af57763882
commit
7a849e6f20
2 changed files with 7 additions and 13 deletions
|
@ -18,6 +18,8 @@ func (tkr *Tracker) HandleAnnounce(ann *models.Announce, w Writer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
if tkr.cfg.Whitelist {
|
if tkr.cfg.Whitelist {
|
||||||
err = conn.FindClient(ann.ClientID())
|
err = conn.FindClient(ann.ClientID())
|
||||||
if err == ErrClientUnapproved {
|
if err == ErrClientUnapproved {
|
||||||
|
@ -86,12 +88,7 @@ func (tkr *Tracker) HandleAnnounce(ann *models.Announce, w Writer) error {
|
||||||
conn.PurgeInactiveTorrent(torrent.Infohash)
|
conn.PurgeInactiveTorrent(torrent.Infohash)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = w.WriteAnnounce(newAnnounceResponse(ann, peer, torrent))
|
return w.WriteAnnounce(newAnnounceResponse(ann, peer, torrent))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateSwarm handles the changes to a torrent's swarm given an announce.
|
// updateSwarm handles the changes to a torrent's swarm given an announce.
|
||||||
|
|
|
@ -8,12 +8,14 @@ import "github.com/chihaya/chihaya/tracker/models"
|
||||||
|
|
||||||
// HandleScrape encapsulates all the logic of handling a BitTorrent client's
|
// HandleScrape encapsulates all the logic of handling a BitTorrent client's
|
||||||
// scrape without being coupled to any transport protocol.
|
// scrape without being coupled to any transport protocol.
|
||||||
func (tkr *Tracker) HandleScrape(scrape *models.Scrape, w Writer) error {
|
func (tkr *Tracker) HandleScrape(scrape *models.Scrape, w Writer) (err error) {
|
||||||
conn, err := tkr.Pool.Get()
|
conn, err := tkr.Pool.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
if tkr.cfg.Private {
|
if tkr.cfg.Private {
|
||||||
_, err = conn.FindUser(scrape.Passkey)
|
_, err = conn.FindUser(scrape.Passkey)
|
||||||
if err == ErrUserDNE {
|
if err == ErrUserDNE {
|
||||||
|
@ -36,10 +38,5 @@ func (tkr *Tracker) HandleScrape(scrape *models.Scrape, w Writer) error {
|
||||||
torrents = append(torrents, torrent)
|
torrents = append(torrents, torrent)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = w.WriteScrape(&models.ScrapeResponse{torrents})
|
return w.WriteScrape(&models.ScrapeResponse{torrents})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn.Close()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue