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

Issue 123610043: code review 123610043: net/http: fix TimeoutHandler data races; hold lock longer (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 8 months ago by bradfitz
Modified:
9 years, 5 months ago
Reviewers:
ruiu, adg, seong
CC:
adg, ruiu, golang-codereviews
Visibility:
Public.

Description

net/http: fix TimeoutHandler data races; hold lock longer The existing lock needed to be held longer. If a timeout occured while writing (but after the guarded timeout check), the writes would clobber a future connection's buffer. Also remove a harmless warning by making Write also set the flag that headers were sent (implicitly), so we don't try to write headers later (a no-op + warning) on timeout after we've started writing. Fixes Issue 8414 Fixes Issue 8209

Patch Set 1 #

Patch Set 2 : diff -r 3cf190969915d6d531acd0795eb81974aaa64d19 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 3cf190969915d6d531acd0795eb81974aaa64d19 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 3cf190969915d6d531acd0795eb81974aaa64d19 https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 5 : diff -r 3cf190969915d6d531acd0795eb81974aaa64d19 https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r 7e00313f3b3a14e59d607aaab84416289dbc76f6 https://go.googlecode.com/hg/ #

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

Messages

Total messages: 10
bradfitz
Hello adg@golang.org (cc: golang-codereviews@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
9 years, 8 months ago (2014-08-19 19:33:07 UTC) #1
ruiu
Is WriteHeader safe? If a timeout occurred while WriteHeader is writing, would it clobber the ...
9 years, 8 months ago (2014-08-19 19:46:49 UTC) #2
bradfitz
Good point. On Aug 19, 2014 12:46 PM, <ruiu@google.com> wrote: > Is WriteHeader safe? If ...
9 years, 8 months ago (2014-08-19 19:51:35 UTC) #3
bradfitz
Hello adg@golang.org, ruiu@google.com (cc: golang-codereviews@googlegroups.com), Please take another look.
9 years, 8 months ago (2014-08-19 20:22:15 UTC) #4
bradfitz
PTAL. Fixed WriteHeader too and added another test. Both tests previously failed and work now. ...
9 years, 8 months ago (2014-08-19 20:22:28 UTC) #5
ruiu
LGTM with this fix. https://codereview.appspot.com/123610043/diff/60001/src/pkg/net/http/serve_test.go File src/pkg/net/http/serve_test.go (right): https://codereview.appspot.com/123610043/diff/60001/src/pkg/net/http/serve_test.go#newcode1263 src/pkg/net/http/serve_test.go:1263: res.Body.Close() res.Body.Close() called twice at ...
9 years, 8 months ago (2014-08-19 20:28:17 UTC) #6
adg
typo in CL description "warming"
9 years, 8 months ago (2014-08-20 00:58:27 UTC) #7
adg
LGTM after ruiu comments
9 years, 8 months ago (2014-08-20 01:02:43 UTC) #8
bradfitz
*** Submitted as https://code.google.com/p/go/source/detail?r=0ec777d94204 *** net/http: fix TimeoutHandler data races; hold lock longer The existing ...
9 years, 8 months ago (2014-08-20 01:45:11 UTC) #9
seong
9 years, 5 months ago (2014-11-24 14:52:26 UTC) #10
Message was sent while issue was closed.
Created a slight modification to the test:

diff -r 493ad916c3b1 src/net/http/serve_test.go
--- a/src/net/http/serve_test.go	Sun Nov 23 15:13:48 2014 -0500
+++ b/src/net/http/serve_test.go	Mon Nov 24 15:50:11 2014 +0100
@@ -1171,6 +1171,7 @@
 	sendHi := make(chan bool, 1)
 	writeErrors := make(chan error, 1)
 	sayHi := HandlerFunc(func(w ResponseWriter, r *Request) {
+		w.Header().Set("Content-Type", "text/plain")
 		<-sendHi
 		_, werr := w.Write([]byte("hi"))
 		writeErrors <- werr

Assuming a handler modifies the header before timing out. This will lead to a
data race.
Sign in to reply to this message.

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