Skip to content

Commit

Permalink
fix: check channel cancel on pause / resume (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc authored Oct 15, 2021
1 parent afb4572 commit 71c22f5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions transport/graphsync/graphsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,12 @@ func (c *dtChannel) pause() error {
c.lk.Lock()
defer c.lk.Unlock()

// Check if the channel was already cancelled
if c.gsKey == nil {
log.Debugf("%s: channel was cancelled so not pausing channel", c.channelID)
return nil
}

// If it's a graphsync request
if c.gsKey.p == c.peerID {
// Pause the request
Expand All @@ -1091,6 +1097,12 @@ func (c *dtChannel) resume(msg datatransfer.Message) error {
c.lk.Lock()
defer c.lk.Unlock()

// Check if the channel was already cancelled
if c.gsKey == nil {
log.Debugf("%s: channel was cancelled so not resuming channel", c.channelID)
return nil
}

var extensions []graphsync.ExtensionData
if msg != nil {
var err error
Expand Down Expand Up @@ -1130,6 +1142,11 @@ func (c *dtChannel) close(ctx context.Context) error {
c.lk.Lock()
defer c.lk.Unlock()

// Check if the channel was already cancelled
if c.gsKey == nil {
return nil
}

// If it's a graphsync request
if c.gsKey.p == c.peerID {
// Cancel the request
Expand Down

0 comments on commit 71c22f5

Please sign in to comment.