{"action":"created","issue":{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/2732","repository_url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix","labels_url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/2732/labels{/name}","comments_url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/2732/comments","events_url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/2732/events","html_url":"https://github.com/spring-cloud/spring-cloud-netflix/issues/2732","id":298012923,"number":2732,"title":"Randomized server port registers with management port in eureka","user":{"login":"pcornelissen","id":1177440,"avatar_url":"https://avatars0.githubusercontent.com/u/1177440?v=4","gravatar_id":"","url":"https://api.github.com/users/pcornelissen","html_url":"https://github.com/pcornelissen","followers_url":"https://api.github.com/users/pcornelissen/followers","following_url":"https://api.github.com/users/pcornelissen/following{/other_user}","gists_url":"https://api.github.com/users/pcornelissen/gists{/gist_id}","starred_url":"https://api.github.com/users/pcornelissen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcornelissen/subscriptions","organizations_url":"https://api.github.com/users/pcornelissen/orgs","repos_url":"https://api.github.com/users/pcornelissen/repos","events_url":"https://api.github.com/users/pcornelissen/events{/privacy}","received_events_url":"https://api.github.com/users/pcornelissen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-17T15:35:35Z","updated_at":"2018-02-19T19:33:26Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I encountered a strange behaviour, when I set management and server port to 0 so I can easily start a few local instances, then the eureka client registers the service with the management port.\r\n\r\nMy Setup: Spring Boot 1.5.10 + Edgeware.SR2\r\n\r\n- BookmarksService with server+management port = 0\r\n- Eureka Server\r\n- Zuul: Forwards all requests to BookmarksService instances\r\n\r\nUsing a fixed IP list for ribbon works.\r\nEnabling DiscoveryClient in the bookmarksservice and Zuul leads to JSON 404 error messages produced by the BookmarksService. After a long while of searching I found that the service name seems to be resolved with the management port instead of the correct one.\r\n\r\nI have verified that using the correct port without zuul/ribbon the correct result is returned and using the management port I see the same JSON error message that I see when I am using json.\r\n\r\nThis can be fixed by not using a management port. But that requires additional access control so no one accesses the actuator stuff via zuul.\r\n\r\nThis is the relevant part of the application.yaml with a management port set\r\n```\r\nserver.port: 0\r\nmanagement:\r\n  port: 10000\r\n  context-path: /internal\r\n\r\neureka:\r\n  client:\r\n    serviceUrl:\r\n      defaultZone: http://localhost:8761/eureka/\r\n  instance:\r\n    instance-id: ${spring.application.name}:${random.value}\r\n```\r\n\r\nI also tried to set the management port to a fixed 10000 and this is the result in eureka:\r\n```\r\n<application>\r\n  <name>BOOKMARKS</name>\r\n  <instance>\r\n    <instanceId>bookmarks:96a084044a99b3ea5ce02b05f0c19619</instanceId>\r\n    <hostName>192.168.2.20</hostName>\r\n    <app>BOOKMARKS</app>\r\n    <ipAddr>192.168.2.20</ipAddr>\r\n    <status>UP</status>\r\n    <overriddenstatus>UNKNOWN</overriddenstatus>\r\n    <port enabled=\"true\">10000</port>\r\n    <securePort enabled=\"false\">443</securePort>\r\n    <countryId>1</countryId>\r\n    <dataCenterInfo class=\"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo\">\r\n      <name>MyOwn</name>\r\n    </dataCenterInfo>\r\n    <leaseInfo>\r\n      <renewalIntervalInSecs>30</renewalIntervalInSecs>\r\n      <durationInSecs>90</durationInSecs>\r\n      <registrationTimestamp>1518881421504</registrationTimestamp>\r\n      <lastRenewalTimestamp>1518881421504</lastRenewalTimestamp>\r\n      <evictionTimestamp>0</evictionTimestamp>\r\n      <serviceUpTimestamp>1518881420997</serviceUpTimestamp>\r\n    </leaseInfo>\r\n    <metadata>\r\n      <management.port>10000</management.port>\r\n      <jmx.port>60862</jmx.port>\r\n    </metadata>\r\n    <homePageUrl>http://192.168.2.20:10000/</homePageUrl>\r\n    <statusPageUrl>http://192.168.2.20:10000/internal/info</statusPageUrl>\r\n    <healthCheckUrl>http://192.168.2.20:10000/internal/health</healthCheckUrl>\r\n    <vipAddress>bookmarks</vipAddress>\r\n    <secureVipAddress>bookmarks</secureVipAddress>\r\n    <isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>\r\n    <lastUpdatedTimestamp>1518881421504</lastUpdatedTimestamp>\r\n    <lastDirtyTimestamp>1518881420965</lastDirtyTimestamp>\r\n    <actionType>ADDED</actionType>\r\n  </instance>\r\n```\r\n\r\nWhen I set the server port to a fixed port the problem goes away:\r\n\r\n```\r\n<application>\r\n  <name>BOOKMARKS</name>\r\n  <instance>\r\n    <instanceId>bookmarks:1a0adf92cef53c159e443686a76bc19c</instanceId>\r\n    <hostName>192.168.2.20</hostName>\r\n    <app>BOOKMARKS</app>\r\n    <ipAddr>192.168.2.20</ipAddr>\r\n    <status>UP</status>\r\n    <overriddenstatus>UNKNOWN</overriddenstatus>\r\n    <port enabled=\"true\">9000</port>\r\n    <securePort enabled=\"false\">443</securePort>\r\n    <countryId>1</countryId>\r\n    <dataCenterInfo class=\"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo\">\r\n      <name>MyOwn</name>\r\n    </dataCenterInfo>\r\n    <leaseInfo>\r\n      <renewalIntervalInSecs>30</renewalIntervalInSecs>\r\n      <durationInSecs>90</durationInSecs>\r\n      <registrationTimestamp>1518881585038</registrationTimestamp>\r\n      <lastRenewalTimestamp>1518881585038</lastRenewalTimestamp>\r\n      <evictionTimestamp>0</evictionTimestamp>\r\n      <serviceUpTimestamp>1518881585038</serviceUpTimestamp>\r\n    </leaseInfo>\r\n    <metadata>\r\n      <management.port>10000</management.port>\r\n      <jmx.port>61698</jmx.port>\r\n    </metadata>\r\n    <homePageUrl>http://192.168.2.20:9000/</homePageUrl>\r\n    <statusPageUrl>http://192.168.2.20:10000/internal/info</statusPageUrl>\r\n    <healthCheckUrl>http://192.168.2.20:10000/internal/health</healthCheckUrl>\r\n    <vipAddress>bookmarks</vipAddress>\r\n    <secureVipAddress>bookmarks</secureVipAddress>\r\n    <isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>\r\n    <lastUpdatedTimestamp>1518881585038</lastUpdatedTimestamp>\r\n    <lastDirtyTimestamp>1518881585009</lastDirtyTimestamp>\r\n    <actionType>ADDED</actionType>\r\n  </instance>\r\n\r\n```\r\nMaybe the documentation should state somewhere that eureka discovery doesn't work with randomized ports. This would save a lot of people a lot of Time, I think ;-)\r\nAnd as contrast to #812, this time I don't have the config server (yet)\r\n\r\nI was hoping that the problem was solved already. Turns out https://stackoverflow.com/questions/29637324/spring-cloud-random-port-not-registered-to-eureka is still partially valid. (Although it works with a random port when no management port is set)\r\n \r\n"},"comment":{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/comments/366784922","html_url":"https://github.com/spring-cloud/spring-cloud-netflix/issues/2732#issuecomment-366784922","issue_url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/2732","id":366784922,"user":{"login":"ryanjbaxter","id":524254,"avatar_url":"https://avatars1.githubusercontent.com/u/524254?v=4","gravatar_id":"","url":"https://api.github.com/users/ryanjbaxter","html_url":"https://github.com/ryanjbaxter","followers_url":"https://api.github.com/users/ryanjbaxter/followers","following_url":"https://api.github.com/users/ryanjbaxter/following{/other_user}","gists_url":"https://api.github.com/users/ryanjbaxter/gists{/gist_id}","starred_url":"https://api.github.com/users/ryanjbaxter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryanjbaxter/subscriptions","organizations_url":"https://api.github.com/users/ryanjbaxter/orgs","repos_url":"https://api.github.com/users/ryanjbaxter/repos","events_url":"https://api.github.com/users/ryanjbaxter/events{/privacy}","received_events_url":"https://api.github.com/users/ryanjbaxter/received_events","type":"User","site_admin":false},"created_at":"2018-02-19T19:33:25Z","updated_at":"2018-02-19T19:33:25Z","author_association":"CONTRIBUTOR","body":"The problem comes down to this code\r\nhttps://github.com/spring-cloud/spring-cloud-netflix/blob/1.4.x/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistration.java#L122\r\n\r\nThis event is fired twice when both the management and server port are set.  However we dont distinguish the events so the first one to fire wins.  It seems that it is always the management port but IDK if that is always the case.\r\n\r\n@spencergibb @dsyer do one of you know another way of accessing the port reliably?"}}
{"actor":{"display_login":"ryanjbaxter"}}