spring-cloud / spring-cloud/spring-cloud-consul

Circular dependencies between consul and mongodb health contributor

Open
#837 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
822
Forks
539
Avg merge
9h 31m
Merged PRs (30d)
7

Description

Description
If consul heartbeat it's configured to use actuator health(the default configuration) and we have some mongo repositories on classpath a circular dependency it's created between them:

The dependencies of some of the beans in the application context form a cycle:

   apiController (field private com.sample.service.ReactiveAutenticationService com.sample.controller.ApiController.reactiveAutenticationService)
      ↓
   reactiveAuthenticationServiceImpl (field private com.sample.repository.AccountRepository com.sample.service.ReactiveAuthenticationServiceImpl.accountRepository)
      ↓
   accountRepository defined in com.sample.repository.AccountRepository defined in @EnableReactiveMongoRepositories declared on ApplicationEntryPoint
┌─────┐
|  reactiveMongoTemplate defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.class]
↑     ↓
|  mappingMongoConverter defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.class]
↑     ↓
|  mongoMappingContext defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.class]
↑     ↓
|  consulAutoServiceRegistrationListener defined in class path resource [org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationAutoConfiguration.class]
↑     ↓
|  consulAutoServiceRegistration defined in class path resource [org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationAutoConfiguration.class]
↑     ↓
|  consulServiceRegistry defined in class path resource [org/springframework/cloud/consul/serviceregistry/ConsulServiceRegistryAutoConfiguration.class]
↑     ↓
|  ttlScheduler defined in class path resource [org/springframework/cloud/consul/support/ConsulHeartbeatAutoConfiguration.class]
↑     ↓
|  actuatorHealthStatusProvider defined in class path resource [org/springframework/cloud/consul/support/ConsulHeartbeatAutoConfiguration$ActuatorBasedApplicationStatusProviderConfig.class]
↑     ↓
|  healthEndpoint defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]
↑     ↓
|  healthContributorRegistry defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]
↑     ↓
|  mongoHealthContributor defined in class path resource [org/springframework/boot/actuate/autoconfigure/data/mongo/MongoReactiveHealthContributorAutoConfiguration.class]
└─────┘

If spring.cloud.consul.discovery.heartbeat.use-actuator-health it's set to false then the dependency chain it's broken and everything works.

Sample
Please check the repository here

Versions
Spring boot: 3.1.5
Spring cloud: 2022.0.4
Java: 17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked sample repository and reproduce the cycle using Spring Boot 3.1.5, Spring Cloud 2022.0.4, Java 17, Mongo repositories, and actuator health enabled. Trace the listed Consul heartbeat and Mongo health auto-configuration classes, then verify that the application starts with heartbeat actuator health enabled without requiring it to be set to false.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb, spring, spring-boot
Domain
backend, databases, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.