Skip to content

Commit

Permalink
add TCP dialTimout logs
Browse files Browse the repository at this point in the history
  • Loading branch information
chandan jain authored and jcmturner committed Jul 18, 2022
1 parent d5a586b commit 2a55b92
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net"
"strings"
"time"

"gopkg.in/jcmturner/gokrb5.v7/iana/errorcode"
Expand Down Expand Up @@ -93,22 +94,30 @@ func dialKDCUDP(count int, kdcs map[int]string) (*net.UDPConn, error) {
// dialKDCTCP establishes a TCP connection to a KDC.
func dialKDCTCP(count int, kdcs map[int]string) (*net.TCPConn, error) {
i := 1
var dialTimeoutErrors []string
for i <= count {
tcpAddr, err := net.ResolveTCPAddr("tcp", kdcs[i])
if err != nil {
return nil, fmt.Errorf("error resolving KDC address: %v", err)
}

conn, err := net.DialTimeout("tcp", tcpAddr.String(), 5*time.Second)

if err == nil {
if err := conn.SetDeadline(time.Now().Add(5 * time.Second)); err != nil {
return nil, err
}
// conn is guaranteed to be a TCPConn
return conn.(*net.TCPConn), nil
}
dialTimeoutErrors = append(dialTimeoutErrors, err.Error())
i++
}

if len(dialTimeoutErrors) > 0 {
dialTimeoutError := "'" + strings.Join(dialTimeoutErrors, ",") + "'"
return nil, fmt.Errorf("DialTimeout Error: %v", dialTimeoutError)
}
return nil, errors.New("error in getting a TCP connection to any of the KDCs")
}

Expand Down

0 comments on commit 2a55b92

Please sign in to comment.