Skip to content

Commit

Permalink
fix: dont complete transfer because graphsync request was cancelled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc authored Jan 19, 2021
1 parent cb19d09 commit 270fb6a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions transport/graphsync/graphsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (t *Transport) OpenChannel(ctx context.Context,
}
responseChan, errChan := t.gs.Request(internalCtx, dataSender, root, stor, exts...)

go t.executeGsRequest(ctx, channelID, responseChan, errChan)
go t.executeGsRequest(ctx, internalCtx, channelID, responseChan, errChan)
return nil
}

Expand All @@ -143,7 +143,7 @@ func (t *Transport) consumeResponses(responseChan <-chan graphsync.ResponseProgr
return lastError
}

func (t *Transport) executeGsRequest(ctx context.Context, channelID datatransfer.ChannelID, responseChan <-chan graphsync.ResponseProgress, errChan <-chan error) {
func (t *Transport) executeGsRequest(ctx context.Context, internalCtx context.Context, channelID datatransfer.ChannelID, responseChan <-chan graphsync.ResponseProgress, errChan <-chan error) {
lastError := t.consumeResponses(responseChan, errChan)

if _, ok := lastError.(graphsync.RequestContextCancelledErr); ok {
Expand All @@ -159,9 +159,19 @@ func (t *Transport) executeGsRequest(ctx context.Context, channelID datatransfer
return
}

// TODO: There seems to be a bug in graphsync. I believe it should return
// graphsync.RequestCancelledErr on the errChan if the request's context is
// cancelled, but it doesn't seem to be doing that
if internalCtx.Err() != nil {
log.Warnf("graphsync request cancelled for channel %s", channelID)
return
}

if lastError != nil {
log.Warnf("graphsync error: %s", lastError.Error())
}

log.Debugf("finished executing graphsync request for channel %s", channelID)
err := t.events.OnChannelCompleted(channelID, lastError == nil)
if err != nil {
log.Error(err)
Expand Down

0 comments on commit 270fb6a

Please sign in to comment.