FAQ
Reviewers: dvyukov, bradfitz,

Message:
Hello dvyukov@google.com, bradfitz@golang.org (cc:
golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go


Description:
net/http: fix data race on countReader.n

Fixes issue 4220.

Please review this at http://codereview.appspot.com/6638053/

Affected files:
M src/pkg/net/http/serve_test.go


Index: src/pkg/net/http/serve_test.go
===================================================================
--- a/src/pkg/net/http/serve_test.go
+++ b/src/pkg/net/http/serve_test.go
@@ -1063,7 +1063,7 @@

func (cr countReader) Read(p []byte) (n int, err error) {
n, err = cr.r.Read(p)
- *cr.n += int64(n)
+ atomic.AddInt64(cr.n, int64(n))
return
}

@@ -1081,8 +1081,8 @@
}))
defer ts.Close()

- nWritten := int64(0)
- req, _ := NewRequest("POST", ts.URL,
io.LimitReader(countReader{neverEnding('a'), &nWritten}, limit*200))
+ nWritten := new(int64)
+ req, _ := NewRequest("POST", ts.URL,
io.LimitReader(countReader{neverEnding('a'), nWritten}, limit*200))

// Send the POST, but don't care it succeeds or not. The
// remote side is going to reply and then close the TCP
@@ -1095,7 +1095,7 @@
// the remote side hung up on us before we wrote too much.
_, _ = DefaultClient.Do(req)

- if nWritten > limit*100 {
+ if atomic.LoadInt64(nWritten) > limit*100 {
t.Errorf("handler restricted the request body to %d bytes, but client
managed to write %d",
limit, nWritten)
}

Search Discussions

  • Brad Fitzpatrick at Oct 11, 2012 at 10:04 pm
    LGTM
    On Thu, Oct 11, 2012 at 2:50 PM, wrote:

    Reviewers: dvyukov, bradfitz,

    Message:
    Hello dvyukov@google.com, bradfitz@golang.org (cc:
    golang-dev@googlegroups.com),

    I'd like you to review this change to
    https://code.google.com/p/go


    Description:
    net/http: fix data race on countReader.n

    Fixes issue 4220.

    Please review this at http://codereview.appspot.com/**6638053/<http://codereview.appspot.com/6638053/>

    Affected files:
    M src/pkg/net/http/serve_test.go


    Index: src/pkg/net/http/serve_test.go
    ==============================**==============================**=======
    --- a/src/pkg/net/http/serve_test.**go
    +++ b/src/pkg/net/http/serve_test.**go
    @@ -1063,7 +1063,7 @@

    func (cr countReader) Read(p []byte) (n int, err error) {
    n, err = cr.r.Read(p)
    - *cr.n += int64(n)
    + atomic.AddInt64(cr.n, int64(n))
    return
    }

    @@ -1081,8 +1081,8 @@
    }))
    defer ts.Close()

    - nWritten := int64(0)
    - req, _ := NewRequest("POST", ts.URL, io.LimitReader(countReader{**neverEnding('a'),
    &nWritten}, limit*200))
    + nWritten := new(int64)
    + req, _ := NewRequest("POST", ts.URL, io.LimitReader(countReader{**neverEnding('a'),
    nWritten}, limit*200))

    // Send the POST, but don't care it succeeds or not. The
    // remote side is going to reply and then close the TCP
    @@ -1095,7 +1095,7 @@
    // the remote side hung up on us before we wrote too much.
    _, _ = DefaultClient.Do(req)

    - if nWritten > limit*100 {
    + if atomic.LoadInt64(nWritten) > limit*100 {
    t.Errorf("handler restricted the request body to %d bytes,
    but client managed to write %d",
    limit, nWritten)
    }

  • Dave at Oct 12, 2012 at 12:07 am
    *** Submitted as
    http://code.google.com/p/go/source/detail?r=57736947de5a ***

    net/http: fix data race on countReader.n

    Fixes issue 4220.

    R=dvyukov, bradfitz
    CC=golang-dev
    http://codereview.appspot.com/6638053


    http://codereview.appspot.com/6638053/
  • Dvyukov at Oct 12, 2012 at 8:07 am

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 11, '12 at 9:57p
activeOct 12, '12 at 8:07a
posts4
users3
websitegolang.org

3 users in discussion

Dave: 2 posts Dvyukov: 1 post Brad Fitzpatrick: 1 post

People

Translate

site design / logo © 2021 Grokbase