tun2: goroutine it up fam

This commit is contained in:
Cadey Ratio 2017-03-26 16:11:59 -07:00
parent 7cf2a9a616
commit d25fe6c7e7
1 changed files with 28 additions and 26 deletions

View File

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