Skip to content

Commit

Permalink
fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Jul 23, 2024
1 parent 8efe5be commit 01dad15
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion chain/exchange/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,12 @@ func (c *client) sendRequestToPeer(ctx context.Context, peer peer.ID, req *Reque

connectionStart := build.Clock.Now()

sctx, cancel := context.WithTimeout(ctx, streamOpenTimeout)
defer cancel()

// Open stream to peer.
stream, err := c.host.NewStream(
network.WithNoDial(ctx, "should already have connection"),
network.WithNoDial(sctx, "should already have connection"),
peer,
ChainExchangeProtocolID)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions chain/exchange/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
ShufflePeersPrefix = 16
WriteResDeadline = 60 * time.Second
streamReadDeadline = 10 * time.Second
streamOpenTimeout = 1 * time.Minute
)

type Request struct { // FIXME: Rename. Make private.
Expand Down
5 changes: 4 additions & 1 deletion node/hello/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const ProtocolID = "/fil/hello/1.0.0"

var log = logging.Logger("hello")
var streamDeadline = 10 * time.Second
var streamOpenTimeout = 1 * time.Minute

type HelloMessage struct {
HeaviestTipSet []cid.Cid
Expand Down Expand Up @@ -141,7 +142,9 @@ func (hs *Service) HandleStream(s inet.Stream) {
}

func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
s, err := hs.h.NewStream(ctx, pid, ProtocolID)
sctx, cancel := context.WithTimeout(ctx, streamOpenTimeout)
defer cancel()
s, err := hs.h.NewStream(sctx, pid, ProtocolID)
if err != nil {
return xerrors.Errorf("error opening stream: %w", err)
}
Expand Down

0 comments on commit 01dad15

Please sign in to comment.