fix: stream read timeout

This commit is contained in:
aarshkshah1992 2020-12-17 11:17:10 +05:30
parent be059b4612
commit fad8fa6264
1 changed files with 4 additions and 0 deletions

View File

@ -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()