From 3433020fa6e9307b12a4a7bc9eddfe9b8c6e18f2 Mon Sep 17 00:00:00 2001 From: Paul Banks Date: Fri, 8 Jun 2018 22:27:05 +0100 Subject: [PATCH] Fix roots race with CA setup hammering bug and defensive nil check hit during obscure upgrade scenario --- agent/http.go | 8 ++++++++ connect/resolver.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/agent/http.go b/agent/http.go index 3e95a9722..8c7b4b22b 100644 --- a/agent/http.go +++ b/agent/http.go @@ -417,6 +417,14 @@ func setTranslateAddr(resp http.ResponseWriter, active bool) { // setIndex is used to set the index response header func setIndex(resp http.ResponseWriter, index uint64) { + // If we ever return X-Consul-Index of 0 blocking clients will go into a busy + // loop and hammer us since ?index=0 will never block. It's always safe to + // return index=1 since the very first Raft write is always an internal one + // writing the raft config for the cluster so no user-facing blocking query + // will ever legitimately have an X-Consul-Index of 1. + if index == 0 { + index = 1 + } resp.Header().Set("X-Consul-Index", strconv.FormatUint(index, 10)) } diff --git a/connect/resolver.go b/connect/resolver.go index b65bada06..f2e574553 100644 --- a/connect/resolver.go +++ b/connect/resolver.go @@ -172,7 +172,7 @@ func (cr *ConsulResolver) resolveServiceEntry(entry *api.ServiceEntry) (string, port := entry.Service.Port service := entry.Service.Service - if !entry.Service.Connect.Native { + if entry.Service.Connect != nil && !entry.Service.Connect.Native { service = entry.Service.ProxyDestination }