From e204ce36a2ba698f7e949cbd2b13458cf51a8042 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 21 Jan 2022 14:27:22 -0500 Subject: [PATCH] netutil: in TestLimitListenerSaturation, allow some connections to fail to dial When the listener saturates, the kernel will typically buffer the remaining pending connections (so they will eventually succeed in dialing). However, that behavior is not guaranteed, and it empirically doesn't always hold: a failure was observed in https://build.golang.org/log/5ac7312814bcff4841563be043f28aaefa9b3c90. We do expect to be able to dial at least as many connections as the listener will accept, and we expect every connection that is accepted to be served to completion. Updates golang/go#22926 Change-Id: I4cb39c8f39fda0dcb905f548612ccdf1856f2a66 Reviewed-on: https://go-review.googlesource.com/c/net/+/380155 Trust: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- netutil/listen_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/netutil/listen_test.go b/netutil/listen_test.go index 793a91d3..77304fdc 100644 --- a/netutil/listen_test.go +++ b/netutil/listen_test.go @@ -203,11 +203,17 @@ func TestLimitListenerSaturation(t *testing.T) { wg.Wait() t.Logf("served %d connections (of %d dialed, %d attempted)", served, dialed, attemptsPerWave) - // We expect that the kernel can queue at least attemptsPerWave - // connections at a time (since it's only a small number), so every - // connection should eventually be served. - if served != attemptsPerWave { - t.Errorf("expected %d served", attemptsPerWave) + + // Depending on the kernel's queueing behavior, we could get unlucky + // and drop one or more connections. However, we should certainly + // be able to serve at least max attempts out of each wave. + // (In the typical case, the kernel will queue all of the connections + // and they will all be served successfully.) + if dialed < max { + t.Errorf("expected at least %d dialed", max) + } + if served < dialed { + t.Errorf("expected all dialed connections to be served") } } }