diff --git a/svc.go b/svc.go index 75a3614..78c86ce 100644 --- a/svc.go +++ b/svc.go @@ -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 @@ -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()