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

Issue 6033043: code review 6033043: net/http/httputil: Clean up ReverseProxy maxLatencyWrit... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 3 months ago by cranger
Modified:
13 years, 3 months ago
Reviewers:
albert.strasheim
CC:
golang-dev, bradfitz
Visibility:
Public.

Description

net/http/httputil: Clean up ReverseProxy maxLatencyWriter goroutines. When FlushInterval is specified on ReverseProxy, the ResponseWriter is wrapped with a maxLatencyWriter that periodically flushes in a goroutine. That goroutine was not being cleaned up at the end of the request. This resulted in a panic when Flush() was being called on a ResponseWriter that was closed. The code was updated to always send the done message to the flushLoop() goroutine after copying the body. Futhermore, the code was refactored to allow the test to verify the maxLatencyWriter behavior.

Patch Set 1 : diff -r 762426ee0cca https://code.google.com/p/go #

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

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

Total comments: 13

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

Total comments: 12

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

Unified diffs Side-by-side diffs Delta from patch set Stats (+87 lines, -19 lines) Patch
M src/pkg/net/http/httputil/reverseproxy.go View 1 2 3 4 4 chunks +29 lines, -19 lines 0 comments Download
M src/pkg/net/http/httputil/reverseproxy_test.go View 1 2 3 4 2 chunks +58 lines, -0 lines 0 comments Download

Messages

Total messages: 13
cranger
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
13 years, 3 months ago (2012-04-13 18:51:07 UTC) #1
cranger
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 3 months ago (2012-04-13 19:33:05 UTC) #2
bradfitz
http://codereview.appspot.com/6033043/diff/4005/src/pkg/net/http/httputil/reverseproxy.go File src/pkg/net/http/httputil/reverseproxy.go (right): http://codereview.appspot.com/6033043/diff/4005/src/pkg/net/http/httputil/reverseproxy.go#newcode40 src/pkg/net/http/httputil/reverseproxy.go:40: wrapWriterCallback func(io.Writer) what is this? just for testing? ReverseProxy ...
13 years, 3 months ago (2012-04-16 16:47:36 UTC) #3
cranger
Hello golang-dev@googlegroups.com, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 3 months ago (2012-04-16 17:34:16 UTC) #4
cranger
http://codereview.appspot.com/6033043/diff/4005/src/pkg/net/http/httputil/reverseproxy.go File src/pkg/net/http/httputil/reverseproxy.go (right): http://codereview.appspot.com/6033043/diff/4005/src/pkg/net/http/httputil/reverseproxy.go#newcode40 src/pkg/net/http/httputil/reverseproxy.go:40: wrapWriterCallback func(io.Writer) On 2012/04/16 16:47:36, bradfitz wrote: > what ...
13 years, 3 months ago (2012-04-16 17:34:36 UTC) #5
bradfitz
http://codereview.appspot.com/6033043/diff/2004/src/pkg/net/http/httputil/reverseproxy.go File src/pkg/net/http/httputil/reverseproxy.go (right): http://codereview.appspot.com/6033043/diff/2004/src/pkg/net/http/httputil/reverseproxy.go#newcode22 src/pkg/net/http/httputil/reverseproxy.go:22: var beforeCopyResponse func(io.Writer) might as well name the parameter ...
13 years, 3 months ago (2012-04-16 20:22:40 UTC) #6
cranger
http://codereview.appspot.com/6033043/diff/2004/src/pkg/net/http/httputil/reverseproxy.go File src/pkg/net/http/httputil/reverseproxy.go (right): http://codereview.appspot.com/6033043/diff/2004/src/pkg/net/http/httputil/reverseproxy.go#newcode22 src/pkg/net/http/httputil/reverseproxy.go:22: var beforeCopyResponse func(io.Writer) On 2012/04/16 20:22:40, bradfitz wrote: > ...
13 years, 3 months ago (2012-04-16 21:32:43 UTC) #7
bradfitz
LGTM On Mon, Apr 16, 2012 at 2:32 PM, <cranger@google.com> wrote: > > http://codereview.appspot.com/**6033043/diff/2004/src/pkg/net/** > ...
13 years, 3 months ago (2012-04-18 18:32:49 UTC) #8
bradfitz
*** Submitted as http://code.google.com/p/go/source/detail?r=a615b796570a *** net/http/httputil: Clean up ReverseProxy maxLatencyWriter goroutines. When FlushInterval is specified ...
13 years, 3 months ago (2012-04-18 18:34:29 UTC) #9
albert.strasheim
--- FAIL: TestReverseProxyFlushInterval-42 (0.07 seconds) reverseproxy_test.go:165: grew 88 goroutines; leak? On 2012/04/18 18:34:29, bradfitz wrote: ...
13 years, 3 months ago (2012-04-19 06:11:08 UTC) #10
bradfitz
Is that GOMAXPROCS > 1? Could you try adding a runtime.Gosched / GC / time.Sleep ...
13 years, 3 months ago (2012-04-19 06:16:47 UTC) #11
albert.strasheim
I think it's GOMAXPROCS 42 based on the test name that was printed: TestReverseProxyFlushInterval-42 We've ...
13 years, 3 months ago (2012-04-19 06:23:40 UTC) #12
cranger
13 years, 3 months ago (2012-04-19 15:24:54 UTC) #13
This test seems too dependent on the behavior of the scheduler.  I could
greatly simplify this if I just checked that the flushLoop() returned. Here
is what I am thinking:
http://codereview.appspot.com/6068046

On Wed, Apr 18, 2012 at 11:23 PM, <fullung@gmail.com> wrote:

> I think it's GOMAXPROCS 42 based on the test name that was printed:
>
> TestReverseProxyFlushInterval-**42
>
> We've started doing the following in our ~/.bash_profiles and in Jenkins
> jobs:
>
> export GOMAXPROCS=$[ 1 + $[ RANDOM % 128 ]]
>
> Seems crazy, but it's very useful.
>
>
> On 2012/04/19 06:16:47, bradfitz wrote:
>
>> Is that GOMAXPROCS > 1?
>>
>
>  Could you try adding a runtime.Gosched / GC / time.Sleep (yes, gross)
>>
> in
>
>> there somewhere just to narrow down where it is?  I'll look tomorrow
>>
> too.
>
>  On Wed, Apr 18, 2012 at 11:11 PM, <mailto:fullung@gmail.com> wrote:
>>
>
>  > --- FAIL: TestReverseProxyFlushInterval-****42 (0.07 seconds)
>>
>> > reverseproxy_test.go:165: grew 88 goroutines; leak?
>> >
>> >
>> > On 2012/04/18 18:34:29, bradfitz wrote:
>> >
>> >> *** Submitted as
>> >>
>> >
>>
>
> http://code.google.com/p/go/****source/detail?r=a615b796570a%**
>
3Chttp://code.google.com/p/go/**source/detail?r=a615b796570a%**3E***<http://code.google.com/p/go/**source/detail?r=a615b796570a%3Chttp://code.google.com/p/go/source/detail?r=a615b796570a%3E***>
>
>  >
>> >  net/http/httputil: Clean up ReverseProxy maxLatencyWriter
>>
> goroutines.
>
>> >>
>> >
>> >  When FlushInterval is specified on ReverseProxy, the ResponseWriter
>>
> is
>
>> >> wrapped with a maxLatencyWriter that periodically flushes in a
>> >> goroutine. That goroutine was not being cleaned up at the end of
>>
> the
>
>> >> request. This resulted in a panic when Flush() was being called on
>>
> a
>
>> >> ResponseWriter that was closed.
>> >>
>> >
>> >  The code was updated to always send the done message to the
>> >>
>> > flushLoop()
>> >
>> >> goroutine after copying the body. Futhermore, the code was
>>
> refactored
>
>> >>
>> > to
>> >
>> >> allow the test to verify the maxLatencyWriter behavior.
>> >>
>> >
>> >  R=golang-dev, bradfitz
>> >> CC=golang-dev
>> >>
>>
>
> http://codereview.appspot.com/****6033043%3Chttp://codereview.**
>
appspot.com/6033043<http://codereview.appspot.com/**6033043%3Chttp://codereview.appspot.com/6033043>
> >
>
>  >>
>> >
>> >  Committer: Brad Fitzpatrick <mailto:bradfitz@golang.org>
>> >>
>> >
>> >
>> >
>>
>
> http://codereview.appspot.com/****6033043/%3Chttp://**
>
codereview.appspot.com/**6033043/<http://codereview.appspot.com/**6033043/%3Chttp://codereview.appspot.com/6033043/>
> >
>
>> >
>>
>
>
>
http://codereview.appspot.com/**6033043/<http://codereview.appspot.com/6033043/>
>
Sign in to reply to this message.

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