From e4c7f4cd695fb33b2331005c640e4da4618046e9 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Thu, 17 Dec 2020 11:17:10 +0530 Subject: [PATCH] fix: stream read timeout --- svc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/svc.go b/svc.go index bdde089..1e94413 100644 --- a/svc.go +++ b/svc.go @@ -19,6 +19,8 @@ import ( manet "github.com/multiformats/go-multiaddr/net" ) +var streamReadTimeout = 60 * time.Second + // AutoNATService provides NAT autodetection services to other peers type autoNATService struct { ctx context.Context @@ -50,6 +52,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()