Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #99 from libp2p/fix/timeout-incoming-stream-reads
Browse files Browse the repository at this point in the history
Fix: Stream read timeout
  • Loading branch information
Stebalien committed Feb 25, 2021
2 parents a107453 + e4c7f4c commit 4b9ee56
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
ma "github.com/multiformats/go-multiaddr"
)

var streamReadTimeout = 60 * time.Second

// AutoNATService provides NAT autodetection services to other peers
type autoNATService struct {
ctx context.Context
Expand Down Expand Up @@ -48,6 +50,8 @@ func newAutoNATService(ctx context.Context, c *config) (*autoNATService, error)
}

func (as *autoNATService) handleStream(s network.Stream) {
s.SetReadDeadline(time.Now().Add(streamReadTimeout))

defer s.Close()

pid := s.Conn().RemotePeer()
Expand Down

0 comments on commit 4b9ee56

Please sign in to comment.