Skip to content

Commit ecf116e

Browse files
authored
Merge pull request #2 from dvinubius/patch-1
Prevent race condition on server connection
2 parents 8ca8b96 + 50a1d31 commit ecf116e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

waitgroups/rate-limiting/server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func main() {
2121
}
2222
connections++
2323

24-
go func() {
24+
go func(con net.Conn) {
2525
defer func() {
26-
_ = conn.Close()
26+
_ = con.Close()
2727
atomic.AddInt32(&connections, -1)
2828
}()
2929
if atomic.LoadInt32(&connections) > 3 {
@@ -36,6 +36,6 @@ func main() {
3636
if err != nil {
3737
log.Fatalf("could not write to connection: %v", err)
3838
}
39-
}()
39+
}(conn)
4040
}
4141
}

0 commit comments

Comments
 (0)