Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: argocd login just hangs on 2.4.0 (#9679) #9935

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 16 additions & 6 deletions util/grpc/grpc.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package grpc

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

"context"

"github.com/argoproj/argo-cd/v2/common"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
Expand Down Expand Up @@ -117,7 +116,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 @@ -126,12 +125,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 @@ -144,7 +152,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