From 6f11e928014636fe78f65814a25cbffcbb33b75f Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Mon, 20 Sep 2021 07:43:22 +0200 Subject: [PATCH] stderr debugging for #517 (tls: bad certificate) refs #517 cc @asomers --- rpc/transportmux/transportmux.go | 3 +++ rpc/versionhandshake/versionhandshake.go | 4 ++++ rpc/versionhandshake/versionhandshake_transport_wrappers.go | 3 +++ transport/tls/connect_tls.go | 3 +++ transport/tls/serve_tls.go | 3 +++ 5 files changed, 16 insertions(+) diff --git a/rpc/transportmux/transportmux.go b/rpc/transportmux/transportmux.go index a35c9a8..34b3bbe 100644 --- a/rpc/transportmux/transportmux.go +++ b/rpc/transportmux/transportmux.go @@ -7,6 +7,7 @@ package transportmux import ( "context" + "os" "sync/atomic" "syscall" @@ -15,6 +16,7 @@ import ( "net" "time" + "github.com/kr/pretty" "github.com/zrepl/zrepl/daemon/logging" "github.com/zrepl/zrepl/logger" "github.com/zrepl/zrepl/transport" @@ -151,6 +153,7 @@ func Demux(ctx context.Context, rawListener transport.AuthenticatedListener, lab rawConn, err := rawListener.Accept(ctx) if err != nil { + fmt.Fprintf(os.Stderr, "transportmux.Demux: rawListener.Accept() returned error: %T %s\n%s\n", err, err, pretty.Sprint(err)) if ctx.Err() != nil { return } diff --git a/rpc/versionhandshake/versionhandshake.go b/rpc/versionhandshake/versionhandshake.go index 749535a..f8d3949 100644 --- a/rpc/versionhandshake/versionhandshake.go +++ b/rpc/versionhandshake/versionhandshake.go @@ -10,9 +10,12 @@ import ( "fmt" "io" "net" + "os" "strings" "time" "unicode/utf8" + + "github.com/kr/pretty" ) type HandshakeMessage struct { @@ -93,6 +96,7 @@ func (m *HandshakeMessage) Encode() ([]byte, error) { func (m *HandshakeMessage) DecodeReader(r io.Reader, maxLen int) error { var lenAndSpace [11]byte if _, err := io.ReadFull(r, lenAndSpace[:]); err != nil { + fmt.Fprintf(os.Stderr, "HandshakeMessage.DecodeReader error: %T\n%s", err, pretty.Sprint(err)) return hsIOErr(err, "error reading protocol banner length: %s", err) } if !utf8.Valid(lenAndSpace[:]) { diff --git a/rpc/versionhandshake/versionhandshake_transport_wrappers.go b/rpc/versionhandshake/versionhandshake_transport_wrappers.go index bc176dd..be6e64a 100644 --- a/rpc/versionhandshake/versionhandshake_transport_wrappers.go +++ b/rpc/versionhandshake/versionhandshake_transport_wrappers.go @@ -2,7 +2,9 @@ package versionhandshake import ( "context" + "fmt" "net" + "os" "time" "github.com/zrepl/zrepl/transport" @@ -23,6 +25,7 @@ func (c HandshakeConnecter) Connect(ctx context.Context) (transport.Wire, error) dl = time.Now().Add(c.timeout) } if err := DoHandshakeCurrentVersion(conn, dl); err != nil { + fmt.Fprintf(os.Stderr, "HandshakeConnecter error: %T\n\t%s\n\t%v\n\t%#v\n\n", err, err, err, err) conn.Close() return nil, err } diff --git a/transport/tls/connect_tls.go b/transport/tls/connect_tls.go index 4fc76f9..931bd25 100644 --- a/transport/tls/connect_tls.go +++ b/transport/tls/connect_tls.go @@ -3,7 +3,9 @@ package tls import ( "context" "crypto/tls" + "fmt" "net" + "os" "github.com/pkg/errors" @@ -48,6 +50,7 @@ func TLSConnecterFromConfig(in *config.TLSConnect) (*TLSConnecter, error) { func (c *TLSConnecter) Connect(dialCtx context.Context) (transport.Wire, error) { conn, err := c.dialer.DialContext(dialCtx, "tcp", c.Address) if err != nil { + fmt.Fprintf(os.Stderr, "tls connecter error %T\n\t%s\n\t%v\n\t%#v\n\n", err, err, err, err) return nil, err } tcpConn := conn.(*net.TCPConn) diff --git a/transport/tls/serve_tls.go b/transport/tls/serve_tls.go index dd156cc..0b28384 100644 --- a/transport/tls/serve_tls.go +++ b/transport/tls/serve_tls.go @@ -4,8 +4,10 @@ import ( "context" "crypto/tls" "fmt" + "os" "time" + "github.com/kr/pretty" "github.com/pkg/errors" "github.com/zrepl/zrepl/config" @@ -68,6 +70,7 @@ type tlsAuthListener struct { func (l tlsAuthListener) Accept(ctx context.Context) (*transport.AuthConn, error) { tcpConn, tlsConn, cn, err := l.ClientAuthListener.Accept() if err != nil { + fmt.Fprintf(os.Stderr, "tlsAuthListener.Accept: l.ClientAuthListener.Accept returned error %T %s\n%s\n", err, err, pretty.Sprint(err)) return nil, err } if _, ok := l.clientCNs[cn]; !ok {