Skip to content

Commit

Permalink
Merge pull request #994 from ligustah/fix-crawler-timeout
Browse files Browse the repository at this point in the history
Use timeout context for NewStream call
  • Loading branch information
guillaumemichel authored Oct 23, 2024
2 parents 8170ac4 + 02d373e commit 50b4e99
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ type messageSender struct {

// SendRequest sends a peer a message and waits for its response
func (ms *messageSender) SendRequest(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) {
s, err := ms.h.NewStream(ctx, p, ms.protocols...)
tctx, cancel := context.WithTimeout(ctx, ms.timeout)
defer cancel()

s, err := ms.h.NewStream(tctx, p, ms.protocols...)
if err != nil {
return nil, err
}
Expand All @@ -86,8 +89,6 @@ func (ms *messageSender) SendRequest(ctx context.Context, p peer.ID, pmes *pb.Me
}

r := protoio.NewDelimitedReader(s, network.MessageSizeMax)
tctx, cancel := context.WithTimeout(ctx, ms.timeout)
defer cancel()
defer func() { _ = s.Close() }()

msg := new(pb.Message)
Expand Down

0 comments on commit 50b4e99

Please sign in to comment.