Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13710)

Issue 70410044: code review 70410044: net/http: proactively address potential race in Ser... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 1 month ago by rcrowley
Modified:
10 years, 1 month ago
Reviewers:
gobot, dvyukov, bradfitz
CC:
bradfitz, golang-codereviews
Visibility:
Public.

Description

net/http: proactively address potential race in Server.ConnState The addition of Server.ConnState provides all the necessary hooks to stop a Server gracefully. Users are very likely to reach for sync.WaitGroup before sync/atomic to track active connections, especially considering the warning in the sync/atomic package: "Except for special, low-level applications, synchronization is better done with channels or the facilities of the sync package." The sync.WaitGroup documentation says, "Note that calls with positive delta must happen before the call to Wait, or else Wait may wait for too small a group. Typically this means the calls to Add should execute before the statement creating the goroutine or other event to be waited for." So to allow safe use of a sync.WaitGroup in a Server.ConnState callback, I believe we need to move the conn.setState for StateNew into Server.newConn so it takes place before the goroutine is spawned. https://github.com/rcrowley/go-tigertonic/blob/go1.3/server.go#L42-L43 has an example where I've moved the sync.WaitGroup from net.Conn and net.Listener wrappers into Server.ConnState. I brought this up in https://codereview.appspot.com/69260044/#msg13 but didn't explain it sufficiently. I'm happy to write a test to accompany this change but I'm at a loss for how to write a deterministic test, hence the appeal to documentation and the principle of least surprise.

Patch Set 1 #

Patch Set 2 : diff -r 891e16653547 https://code.google.com/p/go #

Patch Set 3 : diff -r 891e16653547 https://code.google.com/p/go #

Patch Set 4 : diff -r 891e16653547 https://code.google.com/p/go #

Total comments: 2

Patch Set 5 : diff -r 891e16653547 https://code.google.com/p/go #

Patch Set 6 : diff -r 891e16653547 https://code.google.com/p/go #

Patch Set 7 : diff -r 891e16653547 https://code.google.com/p/go #

Patch Set 8 : diff -r 891e16653547 https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+22 lines, -1 line) Patch
M src/pkg/net/http/serve_test.go View 1 2 3 4 5 6 7 1 chunk +21 lines, -0 lines 0 comments Download
M src/pkg/net/http/server.go View 1 2 3 4 5 2 chunks +1 line, -1 line 0 comments Download

Messages

Total messages: 16
rcrowley
Hello bradfitz@golang.org (cc: golang-codereviews@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
10 years, 1 month ago (2014-03-01 23:11:14 UTC) #1
bradfitz
I still see exactly no difference between this and what's already there. What event do ...
10 years, 1 month ago (2014-03-02 00:42:25 UTC) #2
rcrowley
> You writing "I believe we need to move" and your difficulty imagining a > ...
10 years, 1 month ago (2014-03-02 01:46:21 UTC) #3
bradfitz
Sorry, sorry! Okay, I finally understand. Thanks for the explanation and code. You want the ...
10 years, 1 month ago (2014-03-02 02:38:50 UTC) #4
bradfitz
Sorry, that test isn't sufficient. (It's always racy... left the "go" in there) Try this: ...
10 years, 1 month ago (2014-03-02 02:47:01 UTC) #5
rcrowley
> You want the Serve method to not return before successfully-accepted Conns > call the ...
10 years, 1 month ago (2014-03-02 03:20:06 UTC) #6
bradfitz
Please include that new test in this CL too.
10 years, 1 month ago (2014-03-02 03:25:24 UTC) #7
bradfitz
https://codereview.appspot.com/70410044/diff/60001/src/pkg/net/http/server.go File src/pkg/net/http/server.go (right): https://codereview.appspot.com/70410044/diff/60001/src/pkg/net/http/server.go#newcode1724 src/pkg/net/http/server.go:1724: this is unnecessarily whitespacey compared to the rest of ...
10 years, 1 month ago (2014-03-02 03:27:24 UTC) #8
rcrowley
On 2014/03/02 03:25:24, bradfitz wrote: > Please include that new test in this CL too. ...
10 years, 1 month ago (2014-03-02 03:29:07 UTC) #9
rcrowley
https://codereview.appspot.com/70410044/diff/60001/src/pkg/net/http/server.go File src/pkg/net/http/server.go (right): https://codereview.appspot.com/70410044/diff/60001/src/pkg/net/http/server.go#newcode1724 src/pkg/net/http/server.go:1724: On 2014/03/02 03:27:25, bradfitz wrote: > this is unnecessarily ...
10 years, 1 month ago (2014-03-02 03:30:56 UTC) #10
bradfitz
I still don't see the test in this CL, so I've sent you https://codereview.appspot.com/70460043 On ...
10 years, 1 month ago (2014-03-02 03:39:00 UTC) #11
rcrowley
On 2014/03/02 03:39:00, bradfitz wrote: > I still don't see the test in this CL, ...
10 years, 1 month ago (2014-03-02 03:47:54 UTC) #12
bradfitz
LGTM On Sat, Mar 1, 2014 at 7:47 PM, <r@rcrowley.org> wrote: > On 2014/03/02 03:39:00, ...
10 years, 1 month ago (2014-03-02 04:31:57 UTC) #13
bradfitz
*** Submitted as https://code.google.com/p/go/source/detail?r=5db1072ebd76 *** net/http: ensure ConnState for StateNew fires before Server.Serve returns The ...
10 years, 1 month ago (2014-03-02 04:32:53 UTC) #14
gobot
This CL appears to have broken the darwin-386-cheney builder.
10 years, 1 month ago (2014-03-02 05:14:13 UTC) #15
dvyukov
10 years, 1 month ago (2014-03-02 06:24:43 UTC) #16
On 2014/03/02 05:14:13, gobot wrote:
> This CL appears to have broken the darwin-386-cheney builder.

Brad, https://code.google.com/p/go/issues/detail?id=7264 is about a similar
situation in a test.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b