diff --git a/lib/tun2/server.go b/lib/tun2/server.go index 0022c7b..8e0b467 100644 --- a/lib/tun2/server.go +++ b/lib/tun2/server.go @@ -159,40 +159,42 @@ func (s *Server) ListenAndServe() error { s.connlock.Lock() for _, c := range s.conns { - req, err := http.NewRequest("GET", "http://backend/health", nil) - if err != nil { - panic(err) - } + go func() { + req, err := http.NewRequest("GET", "http://backend/health", nil) + if err != nil { + panic(err) + } - ln.Log(c.F(), ln.F{ - "action": "sending_ping", - }) + ln.Log(c.F(), ln.F{ + "action": "sending_ping", + }) - stream, err := c.session.OpenStream() - if err != nil { - ln.Error(err) + stream, err := c.session.OpenStream() + if err != nil { + ln.Error(err) - c.cancel() - } + c.cancel() + } - err = req.Write(stream) - if err != nil { - ln.Error(err) + err = req.Write(stream) + if err != nil { + ln.Error(err) - c.cancel() - } + c.cancel() + } - _, err = ioutil.ReadAll(stream) - if err != nil { - ln.Error(err) - c.cancel() - } + _, err = ioutil.ReadAll(stream) + if err != nil { + ln.Error(err) + c.cancel() + } - stream.Close() + stream.Close() - ln.Log(ln.F{ - "action": "ping_health_is_good", - }, c.F()) + ln.Log(ln.F{ + "action": "ping_health_is_good", + }, c.F()) + }() } s.connlock.Unlock()