Skip to content

Commit

Permalink
Retry on dial up errors and fix go routine leaks (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveenrajmani authored May 2, 2023
1 parent 76612d3 commit 7d9372b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -58,6 +58,8 @@ var (
dataOut uint64
)

const dialTimeout = 1 * time.Second

func printDataOut() {
for {
time.Sleep(time.Second)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 7d9372b

Please sign in to comment.