提交 a94755db 作者: Steven Allen

fix deadlock in bitswap sessions

This deadlock would happen when calling SessionsForBlock (holding
bitswap.sessLk) while the session's main loop was trying to deregister the
session (taking bitswap.sessLk).

I've also defensively added selects on contexts for two other channel writes
just in case.

fixes #4394

...well, it fixes *a* deadlock showing up in that issue, there may be more.

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 218b2995
......@@ -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 {
......@@ -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():
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论