spring-cloud-netflix: Heartbeat failed with response code 401

Hello

i cloned https://github.com/spring-cloud-samples/eureka.git and https://github.com/spring-cloud-samples/feign-eureka.git and compile that via maven.

i start eureka server first, after that the feign client.

after a few seconds i see in the eureka server console:

2015-04-01 11:42:52.309  INFO 18158 --- [nio-8761-exec-4] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=Wed Apr 01 11:42:52 CEST 2015, principal=user, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null}]
2015-04-01 11:43:02.411  INFO 18158 --- [nio-8761-exec-5] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=Wed Apr 01 11:43:02 CEST 2015, principal=user, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null}]
2015-04-01 11:43:02.412  WARN 18158 --- [nio-8761-exec-5] com.netflix.eureka.InstanceRegistry      : DS: Registry: lease doesn't exist, registering resource: HELLOSERVER - 127.0.0.1:HelloServer:7111
2015-04-01 11:43:02.413  WARN 18158 --- [nio-8761-exec-5] c.n.eureka.resources.InstanceResource    : Not Found (Renew): HELLOSERVER - 127.0.0.1:HelloServer:7111
2015-04-01 11:43:02.439  INFO 18158 --- [nio-8761-exec-6] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=Wed Apr 01 11:43:02 CEST 2015, principal=user, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null}]
2015-04-01 11:43:02.459  INFO 18158 --- [nio-8761-exec-6] com.netflix.eureka.InstanceRegistry      : Registered instance id 127.0.0.1:HelloServer:7111 with status UP
2015-04-01 11:43:02.764  INFO 18158 --- [nio-8761-exec-7] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=Wed Apr 01 11:43:02 CEST 2015, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={message=Zugriff verweigert, type=org.springframework.security.access.AccessDeniedException}]
2015-04-01 11:43:02.790  WARN 18158 --- [egister-process] c.netflix.eureka.cluster.PeerEurekaNode  : The replication of HELLOSERVER/127.0.0.1:HelloServer:7111/Register failed with response code 401

This exception occours after 10 seconds again and again.

I debug just a little bit, and maybe there is a problem in one batch task of the eureka server. This one don’t use the credenticals from the config.

My steps are:

git clone https://github.com/spring-cloud-samples/eureka.git
cd eureka/
mvn package
java -jar target/eureka-0.0.1-SNAPSHOT.jar
git clone https://github.com/spring-cloud-samples/feign-eureka.git
cd feign-eureka/server/
mvn package
java -jar target/feign-eureka-hello-server-0.0.1-SNAPSHOT.jar

thanks for you help

p.s: in my project, the same error happend. this is for reproducing the error.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 33 (15 by maintainers)

Commits related to this issue

Most upvoted comments

eureka:
  client:
    service-url: 
        defaultZone: http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

It’s work for me.

I’ve had a hard time with this problem. I was getting always 401 from my Discovery Server

I added instance.hostname on my service and i solved the issue

This is my configuration:

Eureka Server:

`server: port: 8761

spring: application: name: eureka

security: user: name: discUser password: discPassword

eureka: client: register-with-eureka: false fetch-registry: false

server: wait-time-in-ms-when-sync-empty: 0 `

Discovery Client:

`eureka: instance: prefer-ip-address: true hostname: localhost

client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://discUser:discPassword@${eureka.instance.hostname}:8761/eureka/`

Thank you @dsyer!

I believed my eureka server was running in Standalone mode, but I re-read the standalone server documentation again:

http://projects.spring.io/spring-cloud/docs/1.0.1/spring-cloud.html#_standalone_mode

I had thought you simply needed:

server:
  port: 8761

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
  server:
    waitTimeInMsWhenSyncEmpty: 0
security:
  user:
    name: user
    password: password

To ensure standalone mode was enabled I thought all you needed was eureka.client.registerWithEureka and eureka.client.fetchRegistry set to false. When I added the other fields, eureka.instance.hostname and eureka.client.serviceUrl the 401 Auth error disappeared. The same applied when I commented out the eureka.client.serviceUrl so my working version how has the following:

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
#    serviceUrl:
#      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    waitTimeInMsWhenSyncEmpty: 0
security:
  user:
    name: user
    password: password

View difference here: https://github.com/KramKroc/eureka/commit/899a6932d0051cc36f31dc1a3f664e8d6dd5ab60#diff-256c57f5b357be82840a9b2207f0dcd5

In other words, to get this to work on OS-X (and I think linux too) the eureka.instance.hostname had to be set to localhost. I still think there is an issue here with how standalone mode with basic auth behaves on different OS’s and I think the documentation on Standalone mode could be clearer on which specific fields need to be set to ensure standalone mode works.