Skip to content

Commit

Permalink
clean up wantlists on non-session success case
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed May 2, 2017
1 parent f39ac4e commit 47239ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions exchange/bitswap/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []*cid.Cid) (<-chan block
return
}

bs.CancelWants([]*cid.Cid{blk.Cid()}, mses)
remaining.Remove(blk.Cid())
select {
case out <- blk:
Expand Down Expand Up @@ -371,6 +372,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg

for _, ses := range bs.SessionsForBlock(k) {
ses.ReceiveBlock(p, b)
bs.CancelWants([]*cid.Cid{k}, ses.id)
}
log.Debugf("got block %s from %s", b, p)
if err := bs.HasBlock(b); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions exchange/bitswap/bitswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ func TestBasicBitswap(t *testing.T) {
t.Fatal(err)
}

time.Sleep(time.Millisecond * 20)
if len(instances[1].Exchange.GetWantlist()) != 0 {
t.Fatal("shouldnt have anything in wantlist")
}

st0, err := instances[0].Exchange.Stat()
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 47239ec

Please sign in to comment.