skip to Main Content

firstly I’d like to say that this topic might be related to others, but I can’t find a solution for this specific error.
Remembering that this error happens ONLY when I execute my ./mvnw test within the Dockerfile stage and on CI.

Dockerfile:

FROM eclipse-temurin:18.0.2.1_1-jdk-alpine AS test
ENV spring_profiles_active=test
ENV APP=/home/fvapi
WORKDIR $APP
COPY pom.xml mvnw ./
COPY .mvn .mvn
COPY src src
RUN ./mvnw test

On CI it just clones the repo and execute the same ./mvnw test.

The error is a loop, and you can see it here: https://pastebin.com/ar5BPXvp

I think the main point here is:

2022-09-14 04:05:46.254  INFO 131 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Starting...
     2022-09-14 04:06:17.298 ERROR 131 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-2 - Exception during pool initialization.
     
     com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

I have already tried looking for anything related to both HikariPool-2 - Exception during pool initialization, loop HikariPool-2 - Starting and to the com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure, but I found nothing relevant.

I also tried these application.properties

spring.datasource.url=jdbc:mysql://DATABASE_URL_FROM_AWS_RDS/dbname
spring.datasource.username=admin
spring.datasource.password=password
spring.datasource.platform=mysql

spring.jpa.show_sql=true
spring.jpa.properties.hibernate.format_sql=true

and also

spring.datasource.url=jdbc:mysql://DATABASE_URL_FROM_AWS_RDS/dbname?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=admin
spring.datasource.password=password
spring.datasource.platform=mysql

spring.jpa.show_sql=true
spring.jpa.properties.hibernate.format_sql=true

Can someone please give me a light?

PS.: this error only happens when running using docker and on CI. If I try locally, it works.

2

Answers


  1. Chosen as BEST ANSWER

    So, I found out that our CI has no access to our AWS RDS instance, that's why the tests could not be ran on CI. Locally it did not work because the container was reaching the timeout for accessing the RDS, and if I tried localhost instead, it did not point to the host ip, since localhost inside the docker is the container itself, not the host.


  2. com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

    The issue is most likely to be about accessing the database. At initialization time Spring validates the DB with validation query, taking a connection from Hikari Pool. The latter in turn fails to connect the database. You need to double-check the host and the port you are actually trying to connect to and the port exposed by MySQL in CI. From your application.properties I see that you don’t specify port at all

    spring.datasource.url=jdbc:mysql://DATABASE_URL_FROM_AWS_RDS/dbname
    

    T

    spring.datasource.url=jdbc:mysql://DATABASE_URL_FROM_AWS_RDS:DATABASE_PORT_FROM_AWS_RDS/dbname
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search