Skip to content

Commit ef2847b

Browse files
committed
Prevent a router panic when ROUTER_BIND_PORTS_AFTER_SYNC is set
The function that was checking whether the router had synced needed to check the nilness of the target of a pointer, not the pointer itself. I also corrected the logic so that when the routerPtr target was not defined, it says the router has not synced. Fixes bug 1589740 (https://bugzilla.redhat.com/show_bug.cgi?id=1589740)
1 parent 57eaee7 commit ef2847b

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

pkg/cmd/infra/router/template.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ func (o *TemplateRouterOptions) Run() error {
314314
if isTrue(util.Env("ROUTER_USE_PROXY_PROTOCOL", "")) {
315315
checkBackend = metrics.ProxyProtocolHTTPBackendAvailable(u)
316316
}
317-
checkSync := metrics.HasSynced(&ptrTemplatePlugin)
317+
checkSync, err := metrics.HasSynced(&ptrTemplatePlugin)
318+
if err != nil {
319+
return err
320+
}
318321
checkController := metrics.ControllerLive()
319322
liveChecks := []healthz.HealthzChecker{checkController}
320323
if !(isTrue(util.Env("ROUTER_BIND_PORTS_BEFORE_SYNC", ""))) {

pkg/router/metrics/health.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,19 @@ func HTTPBackendAvailable(u *url.URL) healthz.HealthzChecker {
3838

3939
// HasSynced returns a healthz check that verifies the router has been synced at least
4040
// once.
41-
func HasSynced(router **templateplugin.TemplatePlugin) healthz.HealthzChecker {
41+
// routerPtr is a pointer because it may not yet be defined (there's a chicken-and-egg problem
42+
// with when the health checker and router object are set up).
43+
func HasSynced(routerPtr **templateplugin.TemplatePlugin) (healthz.HealthzChecker, error) {
44+
if routerPtr == nil {
45+
return nil, fmt.Errorf("Nil routerPtr passed to HasSynced")
46+
}
47+
4248
return healthz.NamedCheck("has-synced", func(r *http.Request) error {
43-
if router != nil {
44-
if (*router).Router.SyncedAtLeastOnce() == true {
45-
return nil
46-
} else {
47-
return fmt.Errorf("Router not synced")
48-
}
49+
if *routerPtr == nil || !(*routerPtr).Router.SyncedAtLeastOnce() {
50+
return fmt.Errorf("Router not synced")
4951
}
5052
return nil
51-
})
53+
}), nil
5254
}
5355

5456
func ControllerLive() healthz.HealthzChecker {

0 commit comments

Comments
 (0)