Don't leak request slots (fixes #483)

This commit is contained in:
Jakob Borg
2014-08-25 17:45:13 +02:00
parent 5bcf26e324
commit e1f1ae041f
3 changed files with 17 additions and 13 deletions

View File

@@ -26,6 +26,7 @@ package model
import (
"bytes"
"errors"
"fmt"
"math/rand"
"os"
"path/filepath"
@@ -145,8 +146,11 @@ func (p *puller) run() {
}
for {
// Run the pulling loop as long as there are blocks to fetch
if sc, sl := cap(p.requestSlots), len(p.requestSlots); sl != sc {
panic(fmt.Sprintf("Incorrect number of slots; %d != %d", sl, sc))
}
// Run the pulling loop as long as there are blocks to fetch
prevVer, queued = p.queueNeededBlocks(prevVer)
if queued > 0 {
p.errors = 0
@@ -169,6 +173,7 @@ func (p *puller) run() {
}
if p.errors > 0 && p.errors >= queued {
p.requestSlots <- true
break pull
}
@@ -181,6 +186,7 @@ func (p *puller) run() {
if debug {
l.Debugf("%q: pulling loop done", p.repoCfg.ID)
}
p.requestSlots <- true
break pull
}