diff --git a/lib/tun2/server.go b/lib/tun2/server.go index 96dc5b4..d4d294a 100644 --- a/lib/tun2/server.go +++ b/lib/tun2/server.go @@ -168,20 +168,21 @@ func (s *Server) pingLoopInner() { defer s.connlock.Unlock() for _, c := range s.conns { - c.session.SetDeadline(time.Now().Add(time.Second)) - req, err := http.NewRequest("GET", "http://backend/health", nil) if err != nil { panic(err) } + c.conn.SetDeadline(time.Now().Add(time.Second)) stream, err := c.session.OpenStream() if err != nil { ln.Error(err, c.F()) c.cancel() return } + c.conn.SetDeadline(time.Time{}) + stream.SetWriteDeadline(time.Now().Add(time.Second)) err = req.Write(stream) if err != nil { ln.Error(err, c.F()) @@ -189,6 +190,7 @@ func (s *Server) pingLoopInner() { return } + stream.SetReadDeadline(time.Now().Add(time.Second)) _, err = stream.Read(make([]byte, 30)) if err != nil { ln.Error(err, c.F()) @@ -402,6 +404,7 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) { c := conns[rand.Intn(len(conns))] + c.conn.SetDeadline(time.Now().Add(time.Second)) stream, err := c.session.OpenStream() if err != nil { ln.Error(err, ln.F{ @@ -416,6 +419,7 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) { return s.RoundTrip(req) } defer stream.Close() + c.conn.SetDeadline(time.Time{}) err = req.Write(stream) if err != nil {