From 83e8bd8b8fd537572564449a55f44a370085ac07 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 9 Oct 2021 15:37:03 +0200 Subject: [PATCH] fixups cc @asomers --- transport/tls/issue-517/main.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/transport/tls/issue-517/main.go b/transport/tls/issue-517/main.go index 7d7fd4d..a9b4633 100644 --- a/transport/tls/issue-517/main.go +++ b/transport/tls/issue-517/main.go @@ -7,6 +7,7 @@ import ( "log" "os" "strings" + "time" "github.com/zrepl/zrepl/config" "github.com/zrepl/zrepl/transport/tls" @@ -16,6 +17,7 @@ var servConf = config.TLSServe{ ServeCommon: config.ServeCommon{ Type: "tls", }, + HandshakeTimeout: 10 * time.Second, } var clientConf = config.TLSConnect{ @@ -27,7 +29,7 @@ var clientConf = config.TLSConnect{ Cert: "", Key: "", ServerCN: "", - DialTimeout: 0, + DialTimeout: 10 * time.Second, } var ca string @@ -91,22 +93,27 @@ func server() { go func() { defer conn.Close() - log.Printf("handling connection %s", conn) + log.Printf("handling connection %s", conn.RemoteAddr()) _, err = io.Copy(conn, strings.NewReader("here is the server\n")) if err != nil { - log.Printf("%s: respond to client error: %s", conn, err) + log.Printf("%s: respond to client error: %s", conn.RemoteAddr(), err) return } - log.Printf("%s: waiting for client to close connection", conn) + err = conn.CloseWrite() + if err != nil { + log.Printf("%s: failed to close write connection: err", conn.RemoteAddr(), err) + } + + log.Printf("%s: waiting for client to close connection", conn.RemoteAddr()) _, err = io.Copy(io.Discard, conn) if err != nil { - log.Printf("%s: error draining client connection: %s", conn, err) + log.Printf("%s: error draining client connection: %s", conn.RemoteAddr(), err) return } - log.Printf("%s: done", conn) + log.Printf("%s: done", conn.RemoteAddr()) return }() }