Skip to content

Commit

Permalink
fix(storage): abort duplicate adder on context error
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhoward committed May 24, 2023
1 parent 3a58b36 commit d4461cb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/storage/duplicateaddercar.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type DuplicateAdderCar struct {
}

func NewDuplicateAdderCarForStream(ctx context.Context, root cid.Cid, path string, scope types.DagScope, store *DeferredStorageCar, outStream io.Writer) *DuplicateAdderCar {
blockStream := &blockStream{}
blockStream := &blockStream{ctx: ctx}
blockStream.blockBuffer = list.New()
blockStream.cond = sync.NewCond(&blockStream.mu)

Expand Down Expand Up @@ -130,6 +130,7 @@ func (da *DuplicateAdderCar) Close() error {

type blockStream struct {
done bool
ctx context.Context
mu sync.Mutex
cond *sync.Cond
blockBuffer *list.List
Expand Down Expand Up @@ -158,6 +159,11 @@ func (bs *blockStream) Next() (blocks.Block, error) {
defer bs.mu.Unlock()

for {
select {
case <-bs.ctx.Done():
return nil, bs.ctx.Err()
default:
}
if e := bs.blockBuffer.Front(); e != nil {
return bs.blockBuffer.Remove(e).(blocks.Block), nil
}
Expand Down

0 comments on commit d4461cb

Please sign in to comment.