Skip to content

Commit

Permalink
Merge pull request #4407 from ipfs/fix/4394
Browse files Browse the repository at this point in the history
fix deadlock in bitswap sessions
  • Loading branch information
whyrusleeping authored Nov 21, 2017
2 parents 586dd65 + a94755d commit 33c8207
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions exchange/bitswap/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ type interestReq struct {
// still be in the interest cache.
func (s *Session) isLiveWant(c *cid.Cid) bool {
resp := make(chan bool, 1)
s.interestReqs <- interestReq{
select {
case s.interestReqs <- interestReq{
c: c,
resp: resp,
}:
case <-s.ctx.Done():
return false
}

select {
Expand Down Expand Up @@ -278,13 +282,17 @@ func (s *Session) cancel(keys []*cid.Cid) {
}

func (s *Session) cancelWants(keys []*cid.Cid) {
s.cancelKeys <- keys
select {
case s.cancelKeys <- keys:
case <-s.ctx.Done():
}
}

func (s *Session) fetch(ctx context.Context, keys []*cid.Cid) {
select {
case s.newReqs <- keys:
case <-ctx.Done():
case <-s.ctx.Done():
}
}

Expand Down

0 comments on commit 33c8207

Please sign in to comment.