问题描述
Eureka Client注册到Eureka Server后,一直保持着STARTING状态,一直不会变为UP状态。
环境版本信息
spring-boot:2.0.6.RELEASE
spring-cloud-dependencies:Finchley.SR2
问题排查
在GitHub上找到了对应的问题 Instance status keep STARTING in eureka server even it is UP on Local,经过科普后,得知出现这种问题的概率是极低的,但是我遇到的场景是100%必现。再次仔细阅读后发现如下说明
Why this happens
Both
DiscoveryClient
andEurekaAutoServiceRegistration
are initialized inEurekaClientAutoConfiguration
. The latter depends on the former.
HeartbeatThread
thread is started delay:eureka.instance.lease-renewal-interval-in-seconds
can be used to configure delay time. Default is 30s, In our case it is configured as 10s.This means there is race condition between
Main flow
andHeartbeat thread
. Duration registration in heartbeat thread, it serializes instance info to JSON which gets itsstatus
first, thenlastDirtyTimestamp
. Between them,Main flow
does status change inEurekaRegistration#register()
.Further,
EurekaAutoServiceRegistration#start()
is invoked after all bean initialized. This means the cost is up to 10s for all beans' initialization.
后来经过仔细排查,发现应用中一个实现了org.springframework.boot.CommandLineRunner的子类,在项目启动期间,解析Reids缓存中的数据过程中,因为数据结构的异常,导致解析失败。修复该问题后,Eureka Client注册到Eureka Server一切正常。