spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.95k stars 1.29k forks source link

Cannot start config server on temporary git repository availability problems #1760

Open maslano opened 3 years ago

maslano commented 3 years ago

Is your feature request related to a problem? Please describe. There is an option to specify git basedir spring.cloud.config.server.git.basedir to have a static place to checkout git repository to. That said, if such repository exists in a specified location the config server should start even if it cannot pull from it at the moment of start. That happens, when the git repo is gone and config server was already running. But it turns out when it is down during config server startup - the startup fails on spring context initialization.

Describe the solution you'd like Config server should acknowledge the fact that the repository in the specified basedir exists, and startup and serve values from that repository until the remote repository is back online

Additional context I have tested it by disabling git repository host in my firewall rules. The config server runs fine until I restart it. The errors I get:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path res
ource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is org.ecl
ipse.jgit.api.errors.TransportException: ssh://git@bitbucket.myorg.com:7999/apps/config.git: timeout: socket is not established
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1464)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1428)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1319)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1206)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:668)
        ... 149 common frames omitted
Caused by: org.eclipse.jgit.api.errors.TransportException: ssh://git@bitbucket.myorg.com:7999/apps/config.git: timeout: socket is not established
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:254)
        at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306)
        at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200)
        at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.cloneToBasedir(JGitEnvironmentRepository.java:574)
        at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.initClonedRepository(JGitEnvironmentRepository.java:332)
        at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.afterPropertiesSet(JGitEnvironmentRepository.java:251)
        at org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.afterPropertiesSet(MultipleJGitEnvironmentRepository.java:68)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
        ... 162 common frames omitted
Caused by: org.eclipse.jgit.errors.TransportException: ssh://git@bitbucket.myorg.com:7999/apps/config.git: timeout: socket is not established
        at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:192)
        at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:140)
        at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:280)
        at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:170)
        at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:137)
        at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:123)
        at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1271)
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:243)
        ... 170 common frames omitted
Caused by: com.jcraft.jsch.JSchException: timeout: socket is not established
        at com.jcraft.jsch.Util.createSocket(Util.java:394)
        at com.jcraft.jsch.Session.connect(Session.java:215)
        at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:146)
        ... 177 common frames omitted
spencergibb commented 3 years ago

Do you have clone on start enabled?

maslano commented 3 years ago

Yes, should I try without?

maslano commented 3 years ago

I repeated the test with spring.cloud.config.server.git.cloneOnStart: false with the same result. Repository was checked in already, blocked the git host, got the spring config errors ( Error creating bean with name 'defaultEnvironmentRepository')

spring:
  profiles:
    active: local
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: ssh://git@bitbucket.myorg.com:7999/apps/config.git
          force-pull: true
          skipSslValidation: true
          refreshRate: 5
          strictHostKeyChecking: false
          cloneOnStart: false
ThomasVitale commented 3 years ago

A similar suggestion has been made in another issue, for which a PR has been submitted as well: https://github.com/spring-cloud/spring-cloud-config/issues/816