[OPT-2279] Resolve spring context initialization race condition on SchemaInitializingElasticsearchRestClientFactory Created: 23/May/19  Updated: 30/Aug/19  Resolved: 24/May/19

Status: Done
Project: Camunda Optimize
Component/s: backend
Affects Version/s: None
Fix Version/s: 2.5.0, 2.5.0-alpha2

Type: Task Priority: L3 - Default
Reporter: Sebastian Bathke Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Context:
We still suffer from occasional spring context initialization hiccups with

11:26:45.169 [main] WARN  o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'objectMapperFactory' defined in URL [jar:file:/home/jenkins/workspace/cleanup-data-performance/m2-repository/org/camunda/optimize/optimize-backend/2.5.0-SNAPSHOT/optimize-backend-2.5.0-SNAPSHOT.jar!/org/camunda/optimize/service/util/mapper/ObjectMapperFactory.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'restHighLevelClient' defined in class path resource [embeddedOptimizeContext.xml]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticSearchSchemaManager' defined in URL [jar:file:/home/jenkins/workspace/cleanup-data-performance/m2-repository/org/camunda/optimize/optimize-backend/2.5.0-SNAPSHOT/optimize-backend-2.5.0-SNAPSHOT.jar!/org/camunda/optimize/service/es/schema/ElasticSearchSchemaManager.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchMetadataService' defined in URL [jar:file:/home/jenkins/workspace/cleanup-data-performance/m2-repository/org/camunda/optimize/optimize-backend/2.5.0-SNAPSHOT/optimize-backend-2.5.0-SNAPSHOT.jar!/org/camunda/optimize/service/es/schema/ElasticsearchMetadataService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'objectMapperFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?

Investigation on the cause revealed that we misuse the FactoryBean interface in the SchemaInitializingElasticsearchRestClientFactory class. We depend on other beans ,e.g. the objectMapper, however the javadoc of the FactoryBean interface states:

 * <p><b>{@code FactoryBean} is a programmatic contract. Implementations are not
 * supposed to rely on annotation-driven injection or other reflective facilities.</b>
 * {@link #getObjectType()} {@link #getObject()} invocations may arrive early in
 * the bootstrap process, even ahead of any post-processor setup. If you need access
 * other beans, implement {@link BeanFactoryAware} and obtain them programmatically.

AT:

  • SchemaInitializingElasticsearchRestClientFactory obtains dependencies via the beanFactory and not by injection or is initialized with a different approach (e.g. as @Bean)
  • potential other affected implementations of FactoryBean are amended as well
  • SchemaInitializingElasticsearchRestClientFactory is removed from spring xml config

Generated at Wed Nov 13 16:09:37 CET 2019 using JIRA 6.4.6#64021-sha1:33e5b454af4594f54560ac233c30a6e00459507e.