Skip to content

Commit

Permalink
fix: avoid existing on failed dial
Browse files Browse the repository at this point in the history
  • Loading branch information
epomatti committed Jul 12, 2023
1 parent c933f8c commit 70c30d2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ func tcp(w http.ResponseWriter, r *http.Request) {
if err != nil {
errMsg := "Resolution failed:" + err.Error()
log.Println(errMsg)
w.WriteHeader(http.StatusBadRequest)
w.WriteHeader(http.StatusBadGateway)
fmt.Fprint(w, errMsg)
return
}
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
println("Dial failed:", err.Error())
os.Exit(1)
errMsg := "Dial failed:" + err.Error()
log.Println(errMsg)
w.WriteHeader(http.StatusBadGateway)
fmt.Fprint(w, errMsg)
return
}
defer conn.Close()
fmt.Fprint(w, "TCP connection: OK\n")
Expand Down

0 comments on commit 70c30d2

Please sign in to comment.