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

Fire cancel locally even if remote cancel fails #120

Merged
merged 2 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,22 @@ func (m *manager) CloseDataTransferChannel(ctx context.Context, chid datatransfe
log.Warnf("unable to close channel: %w", err)
}

if err := m.dataTransferNetwork.SendMessage(ctx, chst.OtherPeer(), m.cancelMessage(chid)); err != nil {
err = m.dataTransferNetwork.SendMessage(ctx, chst.OtherPeer(), m.cancelMessage(chid))
if err != nil {
err = fmt.Errorf("Unable to send cancel message: %w", err)
_ = m.OnRequestDisconnected(ctx, chid)
log.Warn(err)
}

fsmerr := m.channels.Cancel(chid)
if err != nil {
return err
}
if fsmerr != nil {
return xerrors.Errorf("unable to send cancel to channel FSM: %w", err)
}

return m.channels.Cancel(chid)
return nil
}

// pause a running data transfer channel
Expand Down
7 changes: 6 additions & 1 deletion network/libp2p_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ func (impl *libp2pDataTransferNetwork) openStream(ctx context.Context, id peer.I
if nAttempts == impl.maxStreamOpenAttempts {
return nil, xerrors.Errorf("exhausted %d attempts but failed to open stream, err: %w", impl.maxStreamOpenAttempts, err)
}

d := b.Duration()
time.Sleep(d)
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-time.After(d):
}
}
}

Expand Down