ConsulDiscoveryClient.getServices() throws NPE when Consul has no leader, and the gateway's discovery routes stay empty afterwards
I maintainer di solito rispondono entro 1 giorno
Una pull request collegata è già stata integrata.
- #1041 di @ryanjbaxter — integrata
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- java, spring, spring-boot
- Ambito
- backend, distributed-systems
Direzione di ricerca
Start with ConsulDiscoveryClient.getServices() in ConsulDiscoveryClient.java and ConsulReactiveDiscoveryClient.getServices() in ConsulReactiveDiscoveryClient.java; inspect how a null catalog response and the resulting failure are handled. Then trace how discovery results reach the route locator, including whether errors or empty results replace existing routes. Done means a Consul response without a leader does not turn into a misleading empty service list or leave discovery routes unavailable after leadership returns; add or run focused tests for those cases.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
After a Consul leader election, a Spring Cloud Gateway app that uses discovery-based routes loses all of its routes and keeps returning 404 until the Consul catalog changes again.
While Consul has no leader, GET /v1/catalog/services returns 500 "No cluster leader". ConsulDiscoveryClient.getServices() then calls keySet() on a null body:
Map<String, List<String>> catalogServices = client
.getCatalogServices(properties.getAclToken(), QueryParams.DEFAULT)
.getBody();
return new ArrayList<>(catalogServices.keySet());
ConsulReactiveDiscoveryClient.getServices() logs the exception and returns Flux.empty(), so the discovery route locator rebuilds its routes from an empty service list:
ERROR ConsulReactiveDiscoveryClient : Error getting services from Consul.
java.lang.NullPointerException: Cannot invoke "java.util.Map.keySet()" because "catalogServices" is null
at org.springframework.cloud.consul.discovery.ConsulDiscoveryClient.getServices(ConsulDiscoveryClient.java:104)
at org.springframework.cloud.consul.discovery.reactive.ConsulReactiveDiscoveryClient.lambda$getServices$2(ConsulReactiveDiscoveryClient.java:74)
Once a leader is elected, nothing rebuilds the routes, because the catalog index doesn't change. In our case the gateway returned 404 for every /services/<app>/** route for more than 5 minutes after the election. Registering any service (which changes the catalog index) brought the routes back about 3 seconds later.
How we hit it: a JHipster 9.4.0 microservices app (Spring Boot 4.1.1, Spring Cloud 2025.1.3, spring-cloud-consul 5.0.3) on a kind cluster, with a 3-server Consul 2.1.0 StatefulSet and a reactive gateway using discovery routes.
- Deploy the gateway and two services, all registered with Consul, and check that
/services/<app>/**routes work. - Run
kubectl rollout restart statefulset/consulso Consul elects a new leader. - While there's no leader, the gateway logs the NPE above. After the rollout, every discovery route returns 404 until something changes the catalog.
The code is the same in v5.0.4 and on main (getAllInstances() has the same unchecked getBody()).
I'd expect getServices() to throw an exception that says Consul couldn't answer, rather than an NPE. I'd also expect the reactive client not to turn that failure into an empty service list, since an empty list looks like a valid answer and wipes every route. Either keeping the last known services or propagating the error so the route locator keeps its current routes would avoid the outage.
- Lingua principale
- Java
- Stelle
- 821
- Fork
- 540
- Merge medio
- 14h 22m
- PR unite (30g)
- 16
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di spring-cloud/spring-cloud-consul
-
waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
spring-cloud/spring-cloud-consul#984 ·
I maintainer di solito rispondono entro 1 giorno
-
waiting-for-triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
spring-cloud/spring-cloud-consul#996 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Migrating from Spring boot 3.5.11 to 4.0.3 : reregister-service-on-failure not working anymoreForse già presa @yashdotdev13 l’ha presa 7 giorni fa. Apertawaiting-for-triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
spring-cloud/spring-cloud-consul#954 · 1 commento · 5 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
waiting-for-triage
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
spring-cloud/spring-cloud-consul#951 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
waiting-for-triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
spring-cloud/spring-cloud-consul#950 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di spring-cloud/spring-cloud-consul
Issue simili
-
breaking change bug needs human review not ready priority medium size S
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
martin-francois/symphony-trello#1193 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Mend: dependency security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
status: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
spring-projects/spring-framework#37614 ·
I maintainer di solito rispondono entro 1 giorno