Uploaded image for project: 'Camunda Optimize'
  1. Camunda Optimize
  2. OPT-2279

Resolve spring context initialization race condition on SchemaInitializingElasticsearchRestClientFactory

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Done
    • Priority: L3 - Default
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.0, 2.5.0-alpha2
    • Component/s: backend
    • Labels:
      None

      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

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            sebastian.bathke Sebastian Bathke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: