Skip to content

Commit

Permalink
Merge pull request #164 from fujiwara/close-connections
Browse files Browse the repository at this point in the history
Close connections
  • Loading branch information
jwilder authored May 26, 2023
2 parents f112343 + 5950f8e commit f55ebe3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -141,9 +143,14 @@ func waitForDependencies() {
time.Sleep(waitRetryInterval)
} else if err == nil && resp.StatusCode >= 200 && resp.StatusCode < 300 {
log.Printf("Received %d from %s\n", resp.StatusCode, u.String())
// dispose the response body and close it.
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
return
} else {
log.Printf("Received %d from %s. Sleeping %s\n", resp.StatusCode, u.String(), waitRetryInterval)
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
time.Sleep(waitRetryInterval)
}
}
Expand Down Expand Up @@ -177,6 +184,7 @@ func waitForSocket(scheme, addr string, timeout time.Duration) {
}
if conn != nil {
log.Printf("Connected to %s://%s\n", scheme, addr)
conn.Close()
return
}
}
Expand Down

0 comments on commit f55ebe3

Please sign in to comment.