From 7d9372bbd2378e3da03263ee81ef1e7b5de664c5 Mon Sep 17 00:00:00 2001 From: Praveen raj Mani Date: Tue, 2 May 2023 13:32:32 +0530 Subject: [PATCH] Retry on dial up errors and fix go routine leaks (#5) --- main.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 7463416..c33f238 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2021 MinIO, Inc. +// Copyright (c) 2015-2023 MinIO, Inc. // // This file is part of MinIO Object Storage stack // @@ -58,6 +58,8 @@ var ( dataOut uint64 ) +const dialTimeout = 1 * time.Second + func printDataOut() { for { time.Sleep(time.Second) @@ -114,16 +116,24 @@ func runClient(host string) { b := make([]byte, oneMB) proc := 16 // 16 TCP connections is more than enough to saturate a 100G link. var wg sync.WaitGroup - wg.Add(proc) for i := 0; i < proc; i++ { - conn, err := net.Dial("tcp", host) - if err != nil { - log.Println("Dial-Error", conn, err) - time.Sleep(time.Second) - continue - } + wg.Add(1) go func() { defer wg.Done() + var conn net.Conn + var err error + // Establish the connection. + for { + conn, err = net.Dial("tcp", host) + if err != nil { + log.Println("Dial-Error", conn, err) + time.Sleep(dialTimeout) + continue + } else { + break + } + } + // Use the connection. if err := handleTX(conn, b); err != nil { panic(err) }