tun2: bail and fail hard if the connection is dead

This commit is contained in:
Cadey Ratio 2017-03-27 21:29:08 -07:00
parent 99bc2a10b0
commit a009a9fd0f
1 changed files with 6 additions and 2 deletions

View File

@ -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 {