embedded-consul icon indicating copy to clipboard operation
embedded-consul copied to clipboard

Error on close

Open bendg25 opened this issue 8 years ago • 2 comments

We are seeing the following issue on shutdown, seems like either API incompatibility or no REST service available on embedded consul? Spring-consul v1.2.1 embeded-consul v1.0.0

2017/10/30 13:53:36 [ERR] http: Request GET /v1/agent/service/deregister/ourapp-ut-0, error: method GET not allowed from=127.0.0.1:54805 2017-10-30 13:53:36.387 ERROR 25876 --- [ Thread-21] o.s.c.c.d.AbstractDiscoveryLifecycle : A problem occurred attempting to stop discovery lifecycle

com.ecwid.consul.v1.OperationException: OperationException(statusCode=405, statusMessage='Method Not Allowed', statusContent='method GET not allowed') at com.ecwid.consul.v1.agent.AgentConsulClient.agentServiceDeregister(AgentConsulClient.java:254) at com.ecwid.consul.v1.ConsulClient.agentServiceDeregister(ConsulClient.java:282) at org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry.deregister(ConsulServiceRegistry.java:86) at org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry.deregister(ConsulServiceRegistry.java:41) at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.deregister(AbstractAutoServiceRegistration.java:55) at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.deregister(ConsulAutoServiceRegistration.java:105)

bendg25 avatar Oct 30 '17 13:10 bendg25

Could you prepare some project with failing test which will show this behaviour? Now it's hard to determine what is going one and what is the root cause of this issue.

pszymczyk avatar Feb 19 '19 19:02 pszymczyk

It happens because the spring context is closed AFTER the JUnit @AfterAll callbacks closes Consul.

As a workaround consider

  • Disable deregister feature: System.setProperty("spring.cloud.consul.discovery.deregister", "false")
  • Disable service discovery in tests, you probably don't need it at all - System.setProperty("spring.cloud.consul.discovery.enabled", "false")
  • If you can't live with the above options consider starting a single Consul process per all tests (using some kind of a singleton) and close it using a JVM shutdown hook instead of @AfterAll to make sure the context is closed first.

piotrpolak avatar Apr 09 '19 15:04 piotrpolak