tun2: avoid intN panic

This commit is contained in:
Cadey Ratio 2017-03-26 22:03:06 -07:00
parent aa16ea5e26
commit 1c221cdf6d
1 changed files with 5 additions and 1 deletions

View File

@ -365,7 +365,7 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
val, ok := s.domains.Get(req.Host)
if ok {
conns, ok = val.([]*Connection)
if !ok || len(conns) == 0 {
if !ok {
ln.Error(errors.New("no backend connected"), ln.F{
"action": "no_backend_connected",
"remote": req.RemoteAddr,
@ -385,6 +385,10 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
}
}
if len(conns) == 0 {
return nil, errors.New("no backend connected")
}
c := conns[rand.Intn(len(conns))]
stream, err := c.session.OpenStream()