Skip to content

Commit 7819beb

Browse files
committed
OCPBUGS-50498: cvo: improve error handling on port collision
Return right away to avoid panicking if `net.Listen()` hits an error. Moreover, a more user-friendly log is printed out for the case by wrapping the error with more context.
1 parent 57247f8 commit 7819beb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pkg/cvo/metrics.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ func shutdownHttpServer(parentCtx context.Context, svr *http.Server) {
148148
func startListening(svr *http.Server, tlsConfig *tls.Config, lAddr string, resultChannel chan asyncResult) {
149149
tcpListener, err := net.Listen("tcp", lAddr)
150150
if err != nil {
151-
resultChannel <- asyncResult{name: "HTTPS server", error: err}
151+
resultChannel <- asyncResult{
152+
name: "HTTPS server",
153+
error: fmt.Errorf("failed to listen to the network address %s reserved for cluster-version-operator metrics: %w", lAddr, err),
154+
}
155+
return
152156
}
153157
tlsListener := tls.NewListener(tcpListener, tlsConfig)
154158
klog.Infof("Metrics port listening for HTTPS on %v", lAddr)

0 commit comments

Comments
 (0)