44 "context"
55 "errors"
66 "fmt"
7+ "time"
78
89 "github.com/hannahhoward/go-pubsub"
910 "github.com/ipfs/go-cid"
@@ -25,6 +26,7 @@ import (
2526)
2627
2728var log = logging .Logger ("dt-impl" )
29+ var cancelSendTimeout = 30 * time .Second
2830
2931type manager struct {
3032 dataTransferNetwork network.DataTransferNetwork
@@ -294,24 +296,22 @@ func (m *manager) CloseDataTransferChannel(ctx context.Context, chid datatransfe
294296 log .Warnf ("unable to close channel %s: %s" , chid , err )
295297 }
296298
297- // Send a cancel message to the remote peer
298- log .Infof ("%s: sending cancel channel to %s for channel %s" , m .peerID , chst .OtherPeer (), chid )
299- err = m .dataTransferNetwork .SendMessage (ctx , chst .OtherPeer (), m .cancelMessage (chid ))
300- if err != nil {
301- err = fmt .Errorf ("unable to send cancel message for channel %s to peer %s: %w" ,
302- chid , m .peerID , err )
303- _ = m .OnRequestDisconnected (chid , err )
304- log .Warn (err )
305- }
299+ // Send a cancel message to the remote peer async
300+ go func () {
301+ sctx , cancel := context .WithTimeout (context .Background (), cancelSendTimeout )
302+ defer cancel ()
303+ log .Infof ("%s: sending cancel channel to %s for channel %s" , m .peerID , chst .OtherPeer (), chid )
304+ err = m .dataTransferNetwork .SendMessage (sctx , chst .OtherPeer (), m .cancelMessage (chid ))
305+ if err != nil {
306+ err = fmt .Errorf ("unable to send cancel message for channel %s to peer %s: %w" ,
307+ chid , m .peerID , err )
308+ _ = m .OnRequestDisconnected (chid , err )
309+ log .Warn (err )
310+ }
311+ }()
306312
307313 // Fire a cancel event
308314 fsmerr := m .channels .Cancel (chid )
309- // If it wasn't possible to send a cancel message to the peer, return
310- // that error
311- if err != nil {
312- return err
313- }
314- // If it wasn't possible to fire a cancel event, return that error
315315 if fsmerr != nil {
316316 return xerrors .Errorf ("unable to send cancel to channel FSM: %w" , fsmerr )
317317 }
0 commit comments