Commit eb33dc1f authored by Steven Allen's avatar Steven Allen

gc: fix a potential deadlock

Events:

1. User triggers a GC.
2. User aborts the GC.
3. We fail to delete a block when the output channel is already full.

This is really unlikely to happen in practice but it's still incorrect.

Could be related to #6107

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent 8721ce0a
...@@ -83,7 +83,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn ...@@ -83,7 +83,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
var removed uint64 var removed uint64
loop: loop:
for { for ctx.Err() == nil { // select may not notice that we're "done".
select { select {
case k, ok := <-keychan: case k, ok := <-keychan:
if !ok { if !ok {
...@@ -94,8 +94,11 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn ...@@ -94,8 +94,11 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
removed++ removed++
if err != nil { if err != nil {
errors = true errors = true
output <- Result{Error: &CannotDeleteBlockError{k, err}} select {
//log.Errorf("Error removing key from blockstore: %s", err) case output <- Result{Error: &CannotDeleteBlockError{k, err}}:
case <-ctx.Done():
break loop
}
// continue as error is non-fatal // continue as error is non-fatal
continue loop continue loop
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment