Spring boot application throws UnknownHostException when connecting to a Redis Instnace
search cancel

Spring boot application throws UnknownHostException when connecting to a Redis Instnace

book

Article ID: 294489

calendar_today

Updated On:

Products

Redis for VMware Tanzu

Issue/Introduction

Spring boot app after binding/rebinding to Redis Service Instance is unable to start or throws 
java.net.UnknownHostException.

Symptoms:
Spring boot app after binding/rebinding to Redis Service Instance is unable to start or throws error:
 
[APP/PROC/WEB/0] [OUT] java.net.UnknownHostException: q-s0.redis-instance.services.service-instance-ca44f93f-9447-4b25-a311-0eff6ff7f390.bosh: Name or service not known

Cause

The issue might be caused by any of the following:
  • unhealthy Redis Service Instance
  • network connectivity between your app and Redis Service Instance
  • application is not configured property to connect to Redis Service Instance via TLS

Resolution

Here are some troubleshooting to check what is causing the issue:

1. Check the health of the Redis Service Instance by using Redis-CLI. Detailed steps to connect to Redis-CLI can be found here . Use commands: INFO to check on the server stats or PING to check for connections. 

If you found issues with the commands above, check this troubleshooting guide to see if your issue is listed here . 
Ssh and check the service instance and see if you see any errors in logs, resource usage. If you found any errors, unusual resource usage, please open a support request.

2. If you don't see any issues with step 2. check connectivity from your app to Redis service instance

cf ssh <spring-boot-app-name> or bosh ssh -d <tas-deployment> ssh <any-diego-cell>
you can use commands such as
 

nslookup q-s0.redis-instance.services.service-instance-ca44f93f-9447-4b25-a311-0eff6ff7f390.bosh

 

nc q-s0.redis-instance.services.service-instance-ca44f93f-####-####-####-0eff6ff7f390.bosh 6379

or if TLS is enabled

nc q-s0.redis-instance.services.service-instance-ca44f93f-####-####-####-0eff6ff7f390.bosh 16379


3. If you don't find any issue with Step 2. Check your app's credential to connect to a Redis Service Instance

You can use cf env <spring-boot-app-name> or you can use apps manager. Check the credentials used to connect to Redis Service Instance, find tls_port and tls_version 



if tls_port and tls_version are present, the Spring app will use TLS by default. This is also mentioned on our docs. You will need to configure your app to connect via TLS:

For spring boot 3.1.x
spring.data.redis.ssl.enabled=true 
For spring boot prior to 3.1.x
spring.data.redis.ssl=true

you need to add this in your app's application.properties file. For more info, please see here .