From 1d5c58e22d603cba82ed2e1f3294d6060e95b326 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 26 Mar 2017 15:14:13 -0700 Subject: [PATCH] tun2: pingloop --- lib/tun2/server.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/tun2/server.go b/lib/tun2/server.go index 0dbe173..74ff24d 100644 --- a/lib/tun2/server.go +++ b/lib/tun2/server.go @@ -11,6 +11,7 @@ import ( "net" "net/http" "sync" + "time" "git.xeserv.us/xena/route/database" "github.com/Xe/ln" @@ -139,6 +140,31 @@ func (s *Server) ListenAndServe() error { }() } + go func() { + for { + time.Sleep(5 * time.Second) + + s.connlock.Lock() + + for conn, c := range s.conns { + conn.SetDeadline(time.Now().Add(1 * time.Second)) + req, err := http.NewRequest("GET", "http://backend/health", nil) + if err != nil { + panic(err) + } + + _, err = s.RoundTrip(req) + if err != nil { + ln.Error(err) + + c.cancel() + } + } + + s.connlock.Unlock() + } + }() + return nil }