Skip to content

Commit

Permalink
fix goroutine leaks in repo commands
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Steven Allen <[email protected]>
  • Loading branch information
Stebalien committed Nov 21, 2017
1 parent 016b005 commit b2ee0eb
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,29 @@ order to reclaim hard disk space.
errs := false
for res := range gcOutChan {
if res.Error != nil {
outChan <- &GcResult{Error: res.Error.Error()}
select {
case outChan <- &GcResult{Error: res.Error.Error()}:
case <-req.Context().Done():
return
}
errs = true
} else {
outChan <- &GcResult{Key: res.KeyRemoved}
select {
case outChan <- &GcResult{Key: res.KeyRemoved}:
case <-req.Context().Done():
return
}
}
}
if errs {
res.SetError(fmt.Errorf("encountered errors during gc run"), cmdkit.ErrNormal)
}
} else {
err := corerepo.CollectResult(req.Context(), gcOutChan, func(k *cid.Cid) {
outChan <- &GcResult{Key: k}
select {
case outChan <- &GcResult{Key: k}:
case <-req.Context().Done():
}
})
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
Expand Down Expand Up @@ -291,17 +302,29 @@ var repoVerifyCmd = &oldcmds.Command{
for k := range keys {
_, err := bs.Get(k)
if err != nil {
out <- &VerifyProgress{
select {
case out <- &VerifyProgress{
Msg: fmt.Sprintf("block %s was corrupt (%s)", k, err),
}:
case <-req.Context().Done():
return
}
fails++
}
i++
out <- &VerifyProgress{Progress: i}
select {
case out <- &VerifyProgress{Progress: i}:
case <-req.Context().Done():
return
}
}

if fails == 0 {
out <- &VerifyProgress{Msg: "verify complete, all blocks validated."}
select {
case out <- &VerifyProgress{Msg: "verify complete, all blocks validated."}:
case <-req.Context().Done():
return
}
} else {
res.SetError(fmt.Errorf("verify complete, some blocks were corrupt"), cmdkit.ErrNormal)
}
Expand Down

0 comments on commit b2ee0eb

Please sign in to comment.