Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ecf116e

Browse files
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‎

Lines changed: 3 additions & 3 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /