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

Resolve spring context initialization race condition on SchemaInitializingElasticsearchRestClientFactory

    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

        Activity

        sebastian.bathke Sebastian Bathke created issue -
        sebastian.bathke Sebastian Bathke made changes -
        Field Original Value New Value
        Status Open [ 1 ] In Specification [ 10000 ]
        sebastian.bathke Sebastian Bathke made changes -
        Status In Specification [ 10000 ] In Development [ 10312 ]
        sebastian.bathke Sebastian Bathke made changes -
        Description Context:
        We still suffer from occasional spring context initialization hiccups with
        {code}
        11:26:39,814 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@49993335 - Registering current configuration as safe fallback point
        SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

        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?
        {code}

        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:
        {code}
         * <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.
        {code}


        AT:
        - SchemaInitializingElasticsearchRestClientFactory obtains dependencies via the beanFactory and not by injection
        - potential other implementations of FactoryBean are amended as well
        - SchemaInitializingElasticsearchRestClientFactory is annotated as component and removed from spring xml config
        Context:
        We still suffer from occasional spring context initialization hiccups with
        {code}
        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?
        {code}

        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:
        {code}
         * <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.
        {code}


        AT:
        - SchemaInitializingElasticsearchRestClientFactory obtains dependencies via the beanFactory and not by injection
        - potential other implementations of FactoryBean are amended as well
        - SchemaInitializingElasticsearchRestClientFactory is annotated as component and removed from spring xml config
        sebastian.bathke Sebastian Bathke made changes -
        Description Context:
        We still suffer from occasional spring context initialization hiccups with
        {code}
        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?
        {code}

        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:
        {code}
         * <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.
        {code}


        AT:
        - SchemaInitializingElasticsearchRestClientFactory obtains dependencies via the beanFactory and not by injection
        - potential other implementations of FactoryBean are amended as well
        - SchemaInitializingElasticsearchRestClientFactory is annotated as component and removed from spring xml config
        Context:
        We still suffer from occasional spring context initialization hiccups with
        {code}
        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?
        {code}

        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:
        {code}
         * <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.
        {code}


        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
        sebastian.bathke Sebastian Bathke made changes -
        Status In Development [ 10312 ] In Review [ 10212 ]
        Assignee Sebastian Bathke [ sebastian.bathke ] Michael Wagner [ michael.wagner ]
        michael.wagner Michael Wagner made changes -
        Assignee Michael Wagner [ michael.wagner ]
        Status In Review [ 10212 ] Done [ 10010 ]
        Resolution Fixed [ 1 ]
        johannes.heinemann Johannes Heinemann made changes -
        Fix Version/s 2.5.0-alpha2 [ 15407 ]
        johannes.heinemann Johannes Heinemann made changes -
        Labels current_release
        johannes.heinemann Johannes Heinemann made changes -
        Fix Version/s 2.5.0 [ 15385 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: