Skip to content

Commit 6760f20

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
net/http: scale rstAvoidanceDelay to reduce test flakiness
As far as I can tell, some flakiness is unavoidable in tests that race a large client request write against a server's response when the server doesn't read the full request. It does not appear to be possible to simultaneously ensure that well-behaved clients see EOF instead of ECONNRESET and also prevent misbehaving clients from consuming arbitrary server resources. (See RFC 7230 §6.6 for more detail.) Since there doesn't appear to be a way to cleanly eliminate this source of flakiness, we can instead work around it: we can allow the test to adjust the hard-coded delay if it sees a plausibly-related failure, so that the test can retry with a longer delay. As a nice side benefit, this also allows the tests to run more quickly in the typical case: since the test will retry in case of spurious failures, we can start with an aggressively short delay, and only back off to a longer one if it is really needed on the specific machine running the test. Fixes #57084. Fixes #51104. For #58398. Change-Id: Ia4050679f0777e5eeba7670307a77d93cfce856f Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-race,gotip-linux-amd64-race,gotip-windows-amd64-race Reviewed-on: https://go-review.googlesource.com/c/go/+/527196 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent 545e4f3 commit 6760f20

File tree

4 files changed

+419
-289
lines changed

4 files changed

+419
-289
lines changed

src/net/http/export_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,21 @@ func ResponseWriterConnForTesting(w ResponseWriter) (c net.Conn, ok bool) {
315315
}
316316
return nil, false
317317
}
318+
319+
func init() {
320+
// Set the default rstAvoidanceDelay to the minimum possible value to shake
321+
// out tests that unexpectedly depend on it. Such tests should use
322+
// runTimeSensitiveTest and SetRSTAvoidanceDelay to explicitly raise the delay
323+
// if needed.
324+
rstAvoidanceDelay = 1 * time.Nanosecond
325+
}
326+
327+
// SetRSTAvoidanceDelay sets how long we are willing to wait between calling
328+
// CloseWrite on a connection and fully closing the connection.
329+
func SetRSTAvoidanceDelay(t *testing.T, d time.Duration) {
330+
prevDelay := rstAvoidanceDelay
331+
t.Cleanup(func() {
332+
rstAvoidanceDelay = prevDelay
333+
})
334+
rstAvoidanceDelay = d
335+
}

0 commit comments

Comments
 (0)