From d4e4822cc2e7cdd068ea89a0d6e6ac340393523a Mon Sep 17 00:00:00 2001 From: Ricardo Maraschini Date: Fri, 1 Nov 2024 09:41:54 +0100 Subject: [PATCH] chore: make sure we timeout temporary servers --- pkg/namespaces/namespace-pinger.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/namespaces/namespace-pinger.go b/pkg/namespaces/namespace-pinger.go index 704a019da..197eb3a34 100644 --- a/pkg/namespaces/namespace-pinger.go +++ b/pkg/namespaces/namespace-pinger.go @@ -109,6 +109,13 @@ func (n *NamespacePinger) startTCPEchoServer(ready chan struct{}) (err error) { } defer listener.Close() + deadline := time.Now().Add(30 * time.Second) + tcplistener := listener.(*net.TCPListener) + if err = tcplistener.SetDeadline(deadline); err != nil { + close(ready) + return fmt.Errorf("error setting tcp listener deadline: %w", err) + } + go func() { // XXX: here be dragons. we can't signalize we are ready until // the call to read is done so we artificially sleep for a bit @@ -167,6 +174,12 @@ func (n *NamespacePinger) startUDPEchoServer(ready chan struct{}) (err error) { } defer conn.Close() + deadline := time.Now().Add(30 * time.Second) + if err = conn.SetDeadline(deadline); err != nil { + close(ready) + return fmt.Errorf("error setting udp listener deadline: %w", err) + } + go func() { // XXX: here be dragons. we can't signalize we are ready until // the call to read is done so we artificially sleep for a bit