Skip to content

Commit fa84c77

Browse files
queuelistener: fix testListener goroutine leak (zalando#2506)
Queuelistener continously calls Accept on the testListener which keeps a buffer of last accepted testConnections in the conns channel. The test code races to receive from the same channel so Accept goroutine may occasionally block receiving from the empty channel which would be detected by goroutine leak detector introduced by the zalando#2499. The problem could be reproduced e.g. by running: ``` GODEBUG=tracebackancestors=10 go test ./queuelistener/ -run=TestTeardown/connections_accepted_from_the_wrapped_listener_closed_after_tear_down -count=1000 noleak: 1 active goroutine 2655 [chan receive]: github.com/zalando/skipper/queuelistener.(*testListener).Accept(0xc0000e7830) ... ``` This change avoids blocking Accept on potentially empty channel. Signed-off-by: Alexander Yastrebov <[email protected]>
1 parent 13ccac4 commit fa84c77

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

queuelistener/listener_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ func (l *testListener) Accept() (net.Conn, error) {
8080
select {
8181
case l.conns <- c:
8282
default:
83-
// drop one if cannot store the latest
84-
<-l.conns
83+
// Drop one if cannot store the latest.
84+
// The test might have received a connection in the meantime so do not block.
85+
// Sending is safe as Accept is called from a single goroutine.
86+
select {
87+
case <-l.conns:
88+
default:
89+
}
8590
l.conns <- c
8691
}
8792
}

0 commit comments

Comments
 (0)