Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

fix(network): impl: add timeout in newStreamToPeer call #477

Merged
merged 1 commit into from
Apr 23, 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
6 changes: 5 additions & 1 deletion network/ipfs_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

var log = logging.Logger("bitswap_network")

var connectTimeout = time.Second * 5
var sendMessageTimeout = time.Minute * 10

// NewFromIpfsHost returns a BitSwapNetwork supported by underlying IPFS host.
Expand Down Expand Up @@ -312,7 +313,10 @@ func (bsnet *impl) SendMessage(
p peer.ID,
outgoing bsmsg.BitSwapMessage) error {

s, err := bsnet.newStreamToPeer(ctx, p)
tctx, cancel := context.WithTimeout(ctx, connectTimeout)
defer cancel()
Comment on lines +316 to +317
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken from:

tctx, cancel := context.WithTimeout(ctx, s.opts.SendTimeout)
defer cancel()
if err := s.bsnet.ConnectTo(tctx, s.to); err != nil {
return nil, err
}
stream, err := s.bsnet.newStreamToPeer(tctx, s.to)
if err != nil {
return nil, err
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, I'm not setting the timeout inside newStreamToPeer or as an argument (like msgToStream does) because the current pattern in Connect is embedding the timeout externally in the context passed to newStreamToPeer. But I can change both if we want to go in another direction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine for now.


s, err := bsnet.newStreamToPeer(tctx, p)
if err != nil {
return err
}
Expand Down