Skip to content

Commit

Permalink
chore: make sure we timeout temporary servers
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardomaraschini committed Nov 1, 2024
1 parent 1048513 commit d4e4822
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/namespaces/namespace-pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d4e4822

Please sign in to comment.