Skip to content

Commit

Permalink
Move tls handshake errors to debug
Browse files Browse the repository at this point in the history
This turned out to be a much bigger undertaking
due to how the logs are used in tests

Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Aug 8, 2024
1 parent e9ee2a0 commit ec3cc62
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 127 deletions.
4 changes: 2 additions & 2 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5910,9 +5910,9 @@ func (c *client) doTLSHandshake(typ string, solicit bool, url *url.URL, tlsConfi

if err != nil {
if kind == CLIENT {
c.Errorf("TLS handshake error: %v", err)
c.Debugf("TLS handshake error: %v", err)
} else {
c.Errorf("TLS %s handshake error: %v", typ, err)
c.Debugf("TLS %s handshake error: %v", typ, err)
}
c.closeConnection(TLSHandshakeError)

Expand Down
7 changes: 3 additions & 4 deletions server/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package server
import (
"bufio"
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"io"
Expand All @@ -31,8 +32,6 @@ import (
"testing"
"time"

"crypto/tls"

"github.com/nats-io/jwt/v2"
"github.com/nats-io/nats.go"
"github.com/nats-io/nkeys"
Expand Down Expand Up @@ -2444,7 +2443,7 @@ func TestClientClampMaxSubsErrReport(t *testing.T) {
s1 := RunServer(o1)
defer s1.Shutdown()

l := &captureErrorLogger{errCh: make(chan string, 10)}
l := &captureLogger{logCh: make(chan string, 10)}
s1.SetLogger(l, false, false)

o2 := DefaultOptions()
Expand All @@ -2467,7 +2466,7 @@ func TestClientClampMaxSubsErrReport(t *testing.T) {
t.Helper()
for i := 0; i < 2; i++ {
select {
case errStr := <-l.errCh:
case errStr := <-l.logCh:
if i > 0 {
t.Fatalf("Should not have logged a second time: %s", errStr)
}
Expand Down
16 changes: 8 additions & 8 deletions server/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6675,7 +6675,7 @@ func TestGatewayDuplicateServerName(t *testing.T) {
oa1.Gateway.RejectUnknown = true
sa1 := RunServer(oa1)
defer sa1.Shutdown()
sa1l := &captureErrorLogger{errCh: make(chan string, 100)}
sa1l := &captureLogger{logCh: make(chan string, 100)}
sa1.SetLogger(sa1l, false, false)

oa2 := testGatewayOptionsFromToWithServers(t, "A", "B", sb1)
Expand All @@ -6685,7 +6685,7 @@ func TestGatewayDuplicateServerName(t *testing.T) {
oa2.Routes = RoutesFromStr(fmt.Sprintf("nats://127.0.0.1:%d", oa1.Cluster.Port))
sa2 := RunServer(oa2)
defer sa2.Shutdown()
sa2l := &captureErrorLogger{errCh: make(chan string, 100)}
sa2l := &captureLogger{logCh: make(chan string, 100)}
sa2.SetLogger(sa2l, false, false)

checkClusterFormed(t, sa1, sa2)
Expand All @@ -6707,7 +6707,7 @@ func TestGatewayDuplicateServerName(t *testing.T) {

// Since only servers from "A" have configured outbound to
// cluster "B", only servers on "A" are expected to report error.
for _, errCh := range []chan string{sa1l.errCh, sa2l.errCh} {
for _, errCh := range []chan string{sa1l.logCh, sa2l.logCh} {
checkForDupError(errCh)
}

Expand All @@ -6716,7 +6716,7 @@ func TestGatewayDuplicateServerName(t *testing.T) {
sa1.Shutdown()

// Drain the error channels
for _, errCh := range []chan string{sa1l.errCh, sa2l.errCh} {
for _, errCh := range []chan string{sa1l.logCh, sa2l.logCh} {
for done := false; !done; {
select {
case <-errCh:
Expand Down Expand Up @@ -6749,13 +6749,13 @@ func TestGatewayDuplicateServerName(t *testing.T) {
ob3.Routes = RoutesFromStr(fmt.Sprintf("nats://127.0.0.1:%d", ob2.Cluster.Port))
sb3 := RunServer(ob3)
defer sb3.Shutdown()
sb3l := &captureErrorLogger{errCh: make(chan string, 100)}
sb3l := &captureLogger{logCh: make(chan string, 100)}
sb3.SetLogger(sb3l, false, false)

checkClusterFormed(t, sb1, sb2, sb3)

// It should report the error when trying to create the GW connection
checkForDupError(sb3l.errCh)
checkForDupError(sb3l.logCh)

// Stop this node
sb3.Shutdown()
Expand All @@ -6772,12 +6772,12 @@ func TestGatewayDuplicateServerName(t *testing.T) {
oc.Accounts = []*Account{NewAccount("sys")}
sc := RunServer(oc)
defer sc.Shutdown()
scl := &captureErrorLogger{errCh: make(chan string, 100)}
scl := &captureLogger{logCh: make(chan string, 100)}
sc.SetLogger(scl, false, false)

// It should report the error when trying to create the GW connection
// to cluster "A"
checkForDupError(scl.errCh)
checkForDupError(scl.logCh)
}

func TestGatewayNoPanicOnStartupWithMonitoring(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ func TestJWTAccountImportWrongIssuerAccount(t *testing.T) {
defer s.Shutdown()
buildMemAccResolver(s)

l := &captureErrorLogger{errCh: make(chan string, 2)}
l := &captureLogger{logCh: make(chan string, 2)}
s.SetLogger(l, false, false)

okp, _ := nkeys.FromSeed(oSeed)
Expand Down
Loading

0 comments on commit ec3cc62

Please sign in to comment.