Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont complete transfer because graphsync request was cancelled #134

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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