Skip to content

Commit

Permalink
fix: argocd login just hangs on 2.4.0 #9679
Browse files Browse the repository at this point in the history
Signed-off-by: Xiao Yang <[email protected]>
  • Loading branch information
muma378 committed Jul 11, 2022
1 parent 10324a6 commit c32eaec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/argocd/commands/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ argocd login cd.argoproj.io --core`,
server = "kubernetes"
} else {
server = args[0]
tlsTestResult, err := grpc_util.TestTLS(server)
dialTime := 30 * time.Second
tlsTestResult, err := grpc_util.TestTLS(server, dialTime)
errors.CheckError(err)
if !tlsTestResult.TLS {
if !globalClientOpts.PlainText {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ func init() {
adminUsername = GetEnvWithDefault(EnvAdminUsername, defaultAdminUsername)
AdminPassword = GetEnvWithDefault(EnvAdminPassword, defaultAdminPassword)

tlsTestResult, err := grpcutil.TestTLS(apiServerAddress)
dialTime := 30 * time.Second
tlsTestResult, err := grpcutil.TestTLS(apiServerAddress, dialTime)
CheckError(err)

ArgoCDClientset, err = apiclient.NewClient(&apiclient.ClientOptions{Insecure: true, ServerAddr: apiServerAddress, PlainText: !tlsTestResult.TLS})
Expand Down
21 changes: 16 additions & 5 deletions util/grpc/grpc.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package grpc

import (
"context"
"crypto/tls"
"net"
"runtime/debug"
"strings"
"time"

"context"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -115,7 +115,7 @@ type TLSTestResult struct {
InsecureErr error
}

func TestTLS(address string) (*TLSTestResult, error) {
func TestTLS(address string, dialTime time.Duration) (*TLSTestResult, error) {
if parts := strings.Split(address, ":"); len(parts) == 1 {
// If port is unspecified, assume the most likely port
address += ":443"
Expand All @@ -124,12 +124,21 @@ func TestTLS(address string) (*TLSTestResult, error) {
var tlsConfig tls.Config
tlsConfig.InsecureSkipVerify = true
creds := credentials.NewTLS(&tlsConfig)
conn, err := BlockingDial(context.Background(), "tcp", address, creds)

// Set timeout when dialing to the server
// fix: https://github.com/argoproj/argo-cd/issues/9679
ctx, cancel := context.WithTimeout(context.Background(), dialTime)
defer cancel()

conn, err := BlockingDial(ctx, "tcp", address, creds)
if err == nil {
_ = conn.Close()
testResult.TLS = true
creds := credentials.NewTLS(&tls.Config{})
conn, err := BlockingDial(context.Background(), "tcp", address, creds)
ctx, cancel := context.WithTimeout(context.Background(), dialTime)
defer cancel()

conn, err := BlockingDial(ctx, "tcp", address, creds)
if err == nil {
_ = conn.Close()
} else {
Expand All @@ -142,7 +151,9 @@ func TestTLS(address string) (*TLSTestResult, error) {
// If we get here, we were unable to connect via TLS (even with InsecureSkipVerify: true)
// It may be because server is running without TLS, or because of real issues (e.g. connection
// refused). Test if server accepts plain-text connections
conn, err = BlockingDial(context.Background(), "tcp", address, nil)
ctx, cancel = context.WithTimeout(context.Background(), dialTime)
defer cancel()
conn, err = BlockingDial(ctx, "tcp", address, nil)
if err == nil {
_ = conn.Close()
testResult.TLS = false
Expand Down

0 comments on commit c32eaec

Please sign in to comment.