spring-cloud / spring-cloud/spring-cloud-consul
Support both dynamic mgmt & http ports
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 822
- Forks
- 539
- Avg merge
- 9h 31m
- Merged PRs (30d)
- 7
Description
Using both port 0 for management.server and server causes the following stack trace in 2.1.1.RELEASE:
Stacktrace
java.lang.IllegalArgumentException: createCheck port must be greater than 0
at org.springframework.util.Assert.isTrue(Assert.java:118) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration.createCheck(ConsulAutoRegistration.java:236) ~[spring-cloud-consul-discovery-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration.setCheck(ConsulAutoRegistration.java:129) ~[spring-cloud-consul-discovery-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration.initializePort(ConsulAutoRegistration.java:336) ~[spring-cloud-consul-discovery-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.getRegistration(ConsulAutoServiceRegistration.java:58) ~[spring-cloud-consul-discovery-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.getRegistration(ConsulAutoServiceRegistration.java:33) ~[spring-cloud-consul-discovery-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:137) ~[spring-cloud-commons-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.start(ConsulAutoServiceRegistration.java:73) ~[spring-cloud-consul-discovery-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationListener.onApplicationEvent(ConsulAutoServiceRegistrationListener.java:63) ~[spring-cloud-consul-discovery-2.1.1.RELEASE.jar:2.1.1.RELEASE]
Issue tracing
Tracing through, the issue lies in org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration#getManagementPort which defers to org.springframework.cloud.client.discovery.ManagementServerPortUtils#getPort, which in turn returns 0 as ManagementServerProperties.port is 0.
Appreciate this is more likely an issue with spring-cloud-commons (where ManagementServerPortUtils is defined), but raising here for visibility for others who may stumble down this path
application.yml
management:
server:
port: 0
server:
port: 0
Application
@SpringBootApplication
@EnableDiscoveryClient
public class DemoWebServicesApplication {
public static void main(String[] args) {
SpringApplication.run(DemoWebServicesApplication.class, args);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ConsulAutoRegistration#getManagementPort and follow its call to ManagementServerPortUtils#getPort, using the reported application.yml with both management.server.port and server.port set to 0. Reproduce the startup failure and inspect how the management and HTTP ports are selected for the Consul health check. Done means an application using both dynamic ports starts without the createCheck port error and registers correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100