aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/export_test.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2015-12-14 01:04:07 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2015-12-14 14:55:37 +0000
commit0478f7b9d6e9e0461e67716f003f4dbf26bf634d (patch)
tree5362a6590676b5bb262ab2180e4db384c7592f62 /src/net/http/export_test.go
parent24a7955c74e5617492c256bfad03904d6f169b10 (diff)
downloadgo-0478f7b9d6e9e0461e67716f003f4dbf26bf634d.tar.xz
net/http: fix race in TimeoutHandler
New implementation of TimeoutHandler: buffer everything to memory. All or nothing: either the handler finishes completely within the timeout (in which case the wrapper writes it all), or it misses the timeout and none of it gets written, in which case handler wrapper can reliably print the error response without fear that some of the wrapped Handler's code already wrote to the output. Now the goroutine running the wrapped Handler has its own write buffer and Header copy. Document the limitations. Fixes #9162 Change-Id: Ia058c1d62cefd11843e7a2fc1ae1609d75de2441 Reviewed-on: https://go-review.googlesource.com/17752 Reviewed-by: David Symonds <dsymonds@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/export_test.go')
-rw-r--r--src/net/http/export_test.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/net/http/export_test.go b/src/net/http/export_test.go
index e0ae49afa7..4ccce08b43 100644
--- a/src/net/http/export_test.go
+++ b/src/net/http/export_test.go
@@ -58,10 +58,11 @@ func SetPendingDialHooks(before, after func()) {
func SetTestHookServerServe(fn func(*Server, net.Listener)) { testHookServerServe = fn }
func NewTestTimeoutHandler(handler Handler, ch <-chan time.Time) Handler {
- f := func() <-chan time.Time {
- return ch
+ return &timeoutHandler{
+ handler: handler,
+ timeout: func() <-chan time.Time { return ch },
+ // (no body and nil cancelTimer)
}
- return &timeoutHandler{handler, f, ""}
}
func ResetCachedEnvironment() {