Fail IP lookup with STUN failure (#289)

Resolves #226
This commit is contained in:
David Zhao
2021-12-27 16:43:13 -08:00
committed by GitHub
parent 554baa54f6
commit 472f51cdba
+7 -3
View File
@@ -6,7 +6,6 @@ import (
"net" "net"
"time" "time"
"github.com/livekit/protocol/logger"
"github.com/pion/stun" "github.com/pion/stun"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@@ -17,13 +16,18 @@ func (conf *Config) determineIP() (string, error) {
if len(stunServers) == 0 { if len(stunServers) == 0 {
stunServers = DefaultStunServers stunServers = DefaultStunServers
} }
ip, err := GetExternalIP(stunServers) var err error
for i := 0; i < 3; i++ {
var ip string
ip, err = GetExternalIP(stunServers)
if err == nil { if err == nil {
return ip, nil return ip, nil
} else { } else {
logger.Errorw("could not get external IP", err) time.Sleep(500 * time.Millisecond)
} }
} }
return "", errors.Errorf("could not resolve external IP: %v", err)
}
// use local ip instead // use local ip instead
return GetLocalIPAddress() return GetLocalIPAddress()