Skip to content

Commit

Permalink
Try to ensure both ends of a connection are correctly closed at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
Chupaka committed Jan 17, 2023
1 parent 566da4f commit fc9c75f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ func proxy(local io.ReadWriteCloser, remoteAddr *net.TCPAddr) {
go pipe(remote, local)
}

func pipe(r io.Reader, w io.WriteCloser) {
atomic.AddUint32(&globalStats.pipesActive, 1)
func pipe(r io.ReadCloser, w io.WriteCloser) {
atomic.AddUint32(&globalStats.pipesActive, 1) // increase by 1
defer atomic.AddUint32(&globalStats.pipesActive, ^uint32(0)) // decrease by 1

defer r.Close()
defer w.Close()
io.Copy(w, r)
w.Close()
atomic.AddUint32(&globalStats.pipesActive, ^uint32(0))
}

func getMasterAddr(port string, timeout int) *net.TCPAddr {
Expand Down

0 comments on commit fc9c75f

Please sign in to comment.