eureka client instance registers incorrectly if 'server.port' is set to 0
I created basic service that registers itself with a local Eureka server. The application .yml of my client looks like this:
server:
port: 8001
spring:
application:
name: date-service
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
That works.
When I change 'server.port' to '0' so the port is chosen dynamically then the service doesn't appear to register itself correctly anymore. (It still registers, but with the wrong port, 80).
Being able to use dynamic port would be nice, if one wants to run multiple instances of a service locally without having to create multiple configurations of it (i.e. just relaunch the same thing a few times and have each running instance dynamically pick a port).
I just tried it and it worked. What version are you using?
I recreated it. This used to work, so it is a regression. Though the workaround is to set a port. Random ports were built for testing.
Hi @spencergibb I just tested this with Brixton M4 which has 1.1.0.M4 of cloud-netflix (which is where I am guessing this fix went in?) but I am still having this issue. Here's a test service that you can start up and register to a eureka server. Port is random (server.port is 0) but when it registers multiple instances with the same name/ip (locally) it overwrites them. Here's the test service: https://github.com/shivangshah/test-service
Another weird thing that I found when I was setting server.port to actual values, lets say 8080 and 8081, from the eureka UI, it indeed does show 2 instances running BUT when you click on those instances, they both point to the same url of "info" .. and that is of the one that registered first .. in my case it was 8080 .. Not sure if that's how it's supposed to be?
@shivangshah could you please open a new issue.
I'm trying with Dalston.SR1 same happens. If server.port=0 (random) eureka only show (and gives traffic) to the last registered, leaving formers unusable.
Can we reopen the issue or should i create a new one?
Have you set eurkea.instance.instanceId? Otherwise with port=0 eureka will think it is one instance
Perfect, an instanceId with a random value works. Sorry, i'm still a newbie.
thanks
after that port number is generated....is there anyway i can get that value? If I use "${server.port}" ill get 0.
There is an event ServletWebServerInitializedEvent that you can listen to. @TimB0
@TimB0 I know this is already too late but it may help others. You could have used "${local.server.port}" instead.
This problem of using a random port and the service not registering with the discovery service, is still happening:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
bootstrap.properties, port 0 commented out (defaults to 8080):
# server.port=0
works:
2019-08-08 16:19:01.707 INFO 18020 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SERVICEALPHA/localhost:servicealpha: registering service...
2019-08-08 16:19:01.751 INFO 18020 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/eurekaservice'
2019-08-08 16:19:01.755 INFO 18020 --- [ main] .d.o.m.e.ExampleEurekaServiceApplication : Started ExampleEurekaServiceApplication in 11.2 seconds (JVM running for 12.782)
2019-08-08 16:19:01.764 INFO 18020 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SERVICEALPHA/localhost:servicealpha - registration status: 204
bootstrap.properties, add server.port=0 so that it's using a random port:
server.port=0
result is that it doesn't register with the eureka discovery service anymore:
2019-08-08 16:22:43.758 INFO 19776 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2019-08-08 16:22:43.897 INFO 19776 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 60973 (http) with context path '/eurekaservice'
2019-08-08 16:22:43.900 INFO 19776 --- [ main] .d.o.m.e.ExampleEurekaServiceApplication : Started ExampleEurekaServiceApplication in 10.67 seconds (JVM running for 12.327)
Please use Greenwich.SR2 and if the problem still exists please open a separate issue
Hi. I meet a similar problem server.port = ${random.int[8091,8099]} Eurica client log says that Tomcat started on port(s): 8092 (http) with context path ''" I see on the Eureka server's GUI: Fujitsu:custom-app:8091 as the only registered instance. But it is not the all: On the client side I try this.discoveryClient.getInstances(applicationName); I Use GET on on http://fujitsu:8092/service-instances/custom-app (8092! as Embeded Tomcat logs!! on client- it means that EUREKA sees the embedded instance of Tomcat properly! This is that I see in JSON of ServiceInstance list {instances":[{"port":8093,"host":"Fujitsu","metadata":{"management.port":"8093"},"secure":false,"uri":"http://Fujitsu:8093","instanceId":"Fujitsu:custom-app:8091","serviceId":"CUSTOM-APP","instanceInfo":{"instanceId":"Fujitsu:custom-app:8091","app":"CUSTOM-APP","appGroupName":null,"ipAddr":"10.100.102.5","sid":"na","homePageUrl":"http://Fujitsu:8093/","statusPageUrl":"http://Fujitsu:8093/actuator/info","healthCheckUrl":"http://Fujitsu:8093/actuator/health","secureHealthCheckUrl":null,"vipAddress":"custom-app","secureVipAddress":"custom-app","countryId":1,"dataCenterInfo":{"@class":"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo","name":"MyOwn"},"hostName":"Fujitsu","status":"UP","overriddenStatus":"UNKNOWN","leaseInfo":{"renewalIntervalInSecs":30,"durationInSecs":90,"registrationTimestamp":1575196026084,"lastRenewalTimestamp":1575196235916,"evictionTimestamp":0,"serviceUpTimestamp":1575196025561},"isCoordinatingDiscoveryServer":false,"metadata":{"management.port":"8093"},"lastUpdatedTimestamp":1575196026085,"lastDirtyTimestamp":1575196025406,"actionType":"ADDED","asgName":null},"scheme":null}]} URI is this list is 8093(!) already. It does not work on this port of coarse. But 8092 is mentioned nowhere!