Eureka never unregisters a service

39,381

Solution 1

I realized that self preservation mode was never actually being disabled. It turns out the actual property is

eureka.server.enableSelfPreservation=false

(See DefaultEurekaServerConfig Code), which I haven't found documented anywhere. This resolved my issue.

Solution 2

I made service de-registration work by setting the below values

Eureka server application.yml

eureka:
  server:
    enableSelfPreservation: false

Service application.yml

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 2

The full example is here https://github.com/ExampleDriven/spring-cloud-eureka-example

Share:
39,381
lp1776
Author by

lp1776

Updated on July 09, 2022

Comments

  • lp1776
    lp1776 almost 2 years

    I'm currently facing an issue where Eureka does not unregister a registered service. I've pulled the Eureka server example straight from git hub and made only one change, eureka.enableSelfPreservation = false. My application.yml looks like this:

    server:
      port: 8761
    eureka:
      enableSelfPreservation: false
      client:
        registerWithEureka: false
    fetchRegistry: false
      server:
        waitTimeInMsWhenSyncEmpty: 0
    

    I've read that if 85% of the registered services stop delivering heartbeats within 15 minutes, Eureka assumes the issue is network related and does not de-register the services that are not responding. In my case I have only one service running, so I disabled self-preservation mode. I am abruptly killing the process and Eureka leaves the service registered for what seems like an indefinite amount of time.

    My client's application.yml looks like this:

    eureka:
      instance:
        leaseRenewalIntervalInSeconds: 3
      client:
        healthcheck:
          enabled: true
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
      appInfo:
        replicate:
          interval: 3
        initial:
          replicate:
            time: 3
    spring:
      rabbitmq:
        addresses: ${vcap.services.${PREFIX:}rabbitmq.credentials.uri:amqp://${RABBITMQ_HOST:localhost}:${RABBITMQ_PORT:5672}}
    

    My goal is to create a demo where Eureka quickly detects the service is no longer running and another service that is started can quickly register itself.

    As of now, once the eureka client is started, it registers in 3 seconds. It just never un-registers when the service is abruptly terminated. After I kill the service, the Eureka dashboard reads:

    EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.

    How can I prevent this behavior?

  • DtechNet
    DtechNet almost 9 years
    A pull request to the documentation repo for this issue would probably be very helpful for many others. ... If someone hasn't done so already.
  • Mindwin
    Mindwin almost 5 years
    Aren't these values too short?
  • Peter Szanto
    Peter Szanto almost 5 years
    the values are just examples, based on your use case you have to find the right values. The above setting will put much more load on the eureka server, but it will reduce the risk of forwarding traffic to a non working service
  • Balasubramanian Rengasamy
    Balasubramanian Rengasamy about 2 years
    This resolves my issue