From 035eb475a77d835245d23d6a48f5c929fc649bef Mon Sep 17 00:00:00 2001 From: dfawley Date: Fri, 22 Dec 2017 12:39:56 -0800 Subject: [PATCH] Fix TestGracefulStop flakiness (#1767) --- test/gracefulstop_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/gracefulstop_test.go b/test/gracefulstop_test.go index 0dee6cbe..7ac12b09 100644 --- a/test/gracefulstop_test.go +++ b/test/gracefulstop_test.go @@ -38,6 +38,7 @@ type delayListener struct { acceptCalled chan struct{} allowCloseCh chan struct{} cc *delayConn + dialed bool } func (d *delayListener) Accept() (net.Conn, error) { @@ -70,6 +71,13 @@ func (d *delayListener) allowClientRead() { } func (d *delayListener) Dial(to time.Duration) (net.Conn, error) { + if d.dialed { + // Only hand out one connection (net.Dial can return more even after the + // listener is closed). This is not thread-safe, but Dial should never be + // called concurrently in this environment. + return nil, fmt.Errorf("no more conns") + } + d.dialed = true c, err := net.DialTimeout("tcp", d.Listener.Addr().String(), to) if err != nil { return nil, err