diff --git a/v1/runtime/runtime.go b/v1/runtime/runtime.go index 26d830fa790..38503c5f39d 100644 --- a/v1/runtime/runtime.go +++ b/v1/runtime/runtime.go @@ -854,7 +854,10 @@ func (rt *Runtime) Addrs() []string { // listening on (when in server mode). Returns an empty list if it hasn't // started listening. func (rt *Runtime) DiagnosticAddrs() []string { - if rt.server == nil { + rt.serverInitMtx.RLock() + defer rt.serverInitMtx.RUnlock() + + if rt.serverStatus < ServerInitialized { return nil } diff --git a/v1/test/e2e/testing.go b/v1/test/e2e/testing.go index 844986b7cab..2bcf1712f96 100644 --- a/v1/test/e2e/testing.go +++ b/v1/test/e2e/testing.go @@ -309,7 +309,7 @@ func (t *TestRuntime) WaitForServer() error { retries := 100 // 10 seconds before we give up for range retries { // First make sure it has started listening and we have an address - if t.URL() != "" { + if t.URL() != "" && t.diagnosticAddrsReady() { // Then make sure it has started serving err := t.HealthCheck(t.URL()) if err == nil { @@ -322,6 +322,16 @@ func (t *TestRuntime) WaitForServer() error { return errors.New("API Server not ready in time") } +// diagnosticAddrsReady reports whether every configured diagnostic address has +// been bound. Listeners bind on their own goroutines, so the diagnostic one can +// still be unbound once the main one is serving. +func (t *TestRuntime) diagnosticAddrsReady() bool { + if t.Params.DiagnosticAddrs == nil { + return true + } + return len(t.Runtime.DiagnosticAddrs()) >= len(*t.Params.DiagnosticAddrs) +} + func (t *TestRuntime) WaitForServerStatus(status runtime.ServerStatus) error { delay := time.Duration(100) * time.Millisecond retries := 100 // 10 seconds before we give up