Skip to content

Commit

Permalink
pintracker: do not register operation after putting it in channel
Browse files Browse the repository at this point in the history
This creates a race condition where the items may have been
already pinned before the operation is registered in the tracker.

This may result in operations being left in the tracker and potentially
never completed.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
  • Loading branch information
hsanjuan committed May 2, 2018
1 parent 348bd9f commit 63835fb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pintracker/maptracker/maptracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,15 @@ func (mpt *MapPinTracker) Track(c api.Pin) error {
}
}

mpt.optracker.trackNewOperationCtx(mpt.ctx, c.Cid, operationPin)
mpt.set(c.Cid, api.TrackerStatusPinQueued)

select {
case mpt.pinCh <- c:
mpt.optracker.trackNewOperationCtx(mpt.ctx, c.Cid, operationPin)
default:
err := errors.New("pin queue is full")
mpt.setError(c.Cid, err)
mpt.optracker.cancelOperation(c.Cid)
logger.Error(err.Error())
return err
}
Expand Down Expand Up @@ -331,13 +333,15 @@ func (mpt *MapPinTracker) Untrack(c *cid.Cid) error {
return nil
}

mpt.optracker.trackNewOperationCtx(mpt.ctx, c, operationUnpin)
mpt.set(c, api.TrackerStatusUnpinQueued)

select {
case mpt.unpinCh <- api.PinCid(c):
mpt.optracker.trackNewOperationCtx(mpt.ctx, c, operationUnpin)
default:
err := errors.New("unpin queue is full")
mpt.setError(c, err)
mpt.optracker.cancelOperation(c)
logger.Error(err.Error())
return err
}
Expand Down

0 comments on commit 63835fb

Please sign in to comment.