1
votes

I have a quarkus application that is attempting to connect to a mysql database, both of which are running in docker-compose. The application is up, and serving requests (here is a screenshot of the docker-compose logs showing both the quarkus app and mysql starting): [![docker-compose start logs][1]][1]

To verify the quarkus app is working, I make a request to: http://localhost:8080/health/liveliness. A screenshot is shown below: [![liveliness check][2]][2]

The database is also up and available (to verify you can run mysql -h 192.168.0.4 -P 3306 -u user -p, and when prompted for the password, enter password). You can see screenshots of me being able to login and run a few pseudo commands below:

However, when I make a request that involves running a query against the database, it always times out. The full logs (including the stack trace) is shown below:

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    reading-comprehension-ws_1  | 2020-09-07 21:59:51,526 INFO  [com.con.rea.int.DebugInterceptor] (executor-thread-1) Unique id: 6060ad67-723a-4899-afa4-0811ec9dc3b4 com.connor.reading.dao.AssessmentDao.getAllAssessmentsthrew exception of type class com.connor.reading.exception.SystemException for parameters empty (no parameters)
    reading-comprehension-ws_1  | 2020-09-07 21:59:51,526 INFO  [com.con.rea.int.DebugInterceptor] (executor-thread-1) Unique id: 6060ad67-723a-4899-afa4-0811ec9dc3b4 com.connor.reading.service.AssessmentService.getAssessmentsthrew exception of type class com.connor.reading.exception.SystemException for parameters NULL, NULL
    reading-comprehension-ws_1  | 2020-09-07 21:59:51,526 INFO  [com.con.rea.int.DebugInterceptor] (executor-thread-1) Unique id: 6060ad67-723a-4899-afa4-0811ec9dc3b4 com.connor.reading.controller.AssessmentsApiImpl.getAssessmentsthrew exception of type class com.connor.reading.exception.SystemException for parameters NULL, NULL
    reading-comprehension-ws_1  | 2020-09-07 21:59:51,526 ERROR [com.con.rea.uti.ExceptionMapperImpl] (executor-thread-1) Handling error: com.connor.reading.exception.SystemException: There was an error when querying the database for all assessments.  The sql ran was select * from rc.assessments
    reading-comprehension-ws_1  |   at com.connor.reading.dao.AssessmentDao.getAllAssessments(AssessmentDao.java:42)
    reading-comprehension-ws_1  |   at com.connor.reading.dao.AssessmentDao_Subclass.getAllAssessments$$superaccessor2(AssessmentDao_Subclass.zig:368)
    reading-comprehension-ws_1  |   at com.connor.reading.dao.AssessmentDao_Subclass$$function$$2.apply(AssessmentDao_Subclass$$function$$2.zig:29)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    reading-comprehension-ws_1  |   at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:33)
    reading-comprehension-ws_1  |   at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    reading-comprehension-ws_1  |   at com.connor.reading.dao.AssessmentDao_Subclass.getAllAssessments(AssessmentDao_Subclass.zig:326)
    reading-comprehension-ws_1  |   at com.connor.reading.service.AssessmentService.getAssessments(AssessmentService.java:32)
    reading-comprehension-ws_1  |   at com.connor.reading.service.AssessmentService_Subclass.getAssessments$$superaccessor1(AssessmentService_Subclass.zig:241)
    reading-comprehension-ws_1  |   at com.connor.reading.service.AssessmentService_Subclass$$function$$1.apply(AssessmentService_Subclass$$function$$1.zig:41)
reading-comprehension-ws_1  |   at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    reading-comprehension-ws_1  |   at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:33)
    reading-comprehension-ws_1  |   at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    reading-comprehension-ws_1  |   at com.connor.reading.service.AssessmentService_Subclass.getAssessments(AssessmentService_Subclass.zig:196)
    reading-comprehension-ws_1  |   at com.connor.reading.controller.AssessmentsApiImpl.getAssessments(AssessmentsApiImpl.java:28)
    reading-comprehension-ws_1  |   at com.connor.reading.controller.AssessmentsApiImpl_Subclass.getAssessments$$superaccessor1(AssessmentsApiImpl_Subclass.zig:211)
    reading-comprehension-ws_1  |   at com.connor.reading.controller.AssessmentsApiImpl_Subclass$$function$$1.apply(AssessmentsApiImpl_Subclass$$function$$1.zig:41)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    reading-comprehension-ws_1  |   at com.connor.reading.interceptor.DebugInterceptor.handleAroundInvoke(DebugInterceptor.java:33)
    reading-comprehension-ws_1  |   at com.connor.reading.interceptor.DebugInterceptor_Bean.intercept(DebugInterceptor_Bean.zig:385)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    reading-comprehension-ws_1  |   at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    reading-comprehension-ws_1  |   at com.connor.reading.controller.AssessmentsApiImpl_Subclass.getAssessments(AssessmentsApiImpl_Subclass.zig:166)
    reading-comprehension-ws_1  |   at com.connor.reading.controller.AssessmentsApiImpl_ClientProxy.getAssessments(AssessmentsApiImpl_ClientProxy.zig:195)
    reading-comprehension-ws_1  |   at java.lang.reflect.Method.invoke(Method.java:566)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:638)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:504)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:454)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:456)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:417)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:163)
    reading-comprehension-ws_1  |   at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
    reading-comprehension-ws_1  |   at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
    reading-comprehension-ws_1  |   at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:132)
    reading-comprehension-ws_1  |   at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:37)
    reading-comprehension-ws_1  |   at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:94)
reading-comprehension-ws_1  |   at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    reading-comprehension-ws_1  |   at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
    reading-comprehension-ws_1  |   at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
    reading-comprehension-ws_1  |   at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
    reading-comprehension-ws_1  |   at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
    reading-comprehension-ws_1  |   at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
    reading-comprehension-ws_1  |   at java.lang.Thread.run(Thread.java:834)
    reading-comprehension-ws_1  |   at org.jboss.threads.JBossThread.run(JBossThread.java:479)
    reading-comprehension-ws_1  |   at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
    reading-comprehension-ws_1  |   at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
    reading-comprehension-ws_1  | Caused by: com.connor.quarkus.jdbc.QuarkusDataAccessException: An error occurred
    reading-comprehension-ws_1  |   at com.connor.quarkus.jdbc.QuarkusJdbcTemplate.query(QuarkusJdbcTemplate.java:31)
    reading-comprehension-ws_1  |   at com.connor.reading.dao.AssessmentDao.getAllAssessments(AssessmentDao.java:39)
    reading-comprehension-ws_1  |   ... 61 more
    reading-comprehension-ws_1  | Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
    reading-comprehension-ws_1  | 
    reading-comprehension-ws_1  | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    reading-comprehension-ws_1  |   at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
    reading-comprehension-ws_1  |   at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
    reading-comprehension-ws_1  |   at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
    reading-comprehension-ws_1  |   at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
    reading-comprehension-ws_1  |   at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
    reading-comprehension-ws_1  |   at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
    reading-comprehension-ws_1  |   at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:200)
    reading-comprehension-ws_1  |   at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:419)
    reading-comprehension-ws_1  |   at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:401)
    reading-comprehension-ws_1  |   at java.util.concurrent.FutureTask.run(FutureTask.java:264)
reading-comprehension-ws_1  |   at io.agroal.pool.util.PriorityScheduledExecutor.beforeExecute(PriorityScheduledExecutor.java:65)
    reading-comprehension-ws_1  |   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1126)
    reading-comprehension-ws_1  |   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    reading-comprehension-ws_1  |   at java.lang.Thread.run(Thread.java:834)
    reading-comprehension-ws_1  |   ... 2 more
    reading-comprehension-ws_1  | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
    reading-comprehension-ws_1  | 
    reading-comprehension-ws_1  | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    reading-comprehension-ws_1  |   at java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    reading-comprehension-ws_1  |   at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
    reading-comprehension-ws_1  |   at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
    reading-comprehension-ws_1  |   at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
    reading-comprehension-ws_1  |   at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
    reading-comprehension-ws_1  |   at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91)
    reading-comprehension-ws_1  |   at com.mysql.cj.NativeSession.connect(NativeSession.java:144)
    reading-comprehension-ws_1  |   at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956)
    reading-comprehension-ws_1  |   at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
    reading-comprehension-ws_1  |   ... 13 more
    reading-comprehension-ws_1  | Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
    reading-comprehension-ws_1  |   at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST:Ljava_net_ConnectException_2_0002e_0003cinit_0003e_00028Ljava_lang_String_2_00029V(JNIJavaCallWrappers.java:0)
    reading-comprehension-ws_1  |   at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java)
    reading-comprehension-ws_1  |   at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
    reading-comprehension-ws_1  |   at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
    reading-comprehension-ws_1  |   at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
    reading-comprehension-ws_1  |   at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
    reading-comprehension-ws_1  |   at java.net.Socket.connect(Socket.java:609)
    reading-comprehension-ws_1  |   at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
    reading-comprehension-ws_1  |   at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
    reading-comprehension-ws_1  |   ... 16 more

Repository link: https://gitlab.com/connorbutch/reading-comprehension (on branch 9-list-all-assessments)

The contents of the Docker compose file (used to run the database and application) can be found here: https://gitlab.com/connorbutch/reading-comprehension/-/blob/9-list-all-assessments/reading-comprehension-server-quarkus-impl/infrastructure/docker-compose.yml. For convenience, please find the contents below:

#This file is NOT ever intended for use in production.  Docker-compose is a great tool for running
#database with our application for acceptance testing.
version: '3.3'

#Assign a static ip to the database so that it runs the same on gitlab ci server (as the localhost alias does not work with docker:dind as a service)
networks:
  network:
    ipam:
      driver: default
      config:
        - subnet: 192.168.0.0/24
services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: 'rc'
      MYSQL_USER: 'user'
      MYSQL_PASSWORD: 'password'
      MYSQL_ROOT_PASSWORD: 'password'
    ports:
      - '3306:3306'
    expose:
      - '3306'
    volumes:
      - my-db:/var/lib/mysql
    networks:
      network:
        ipv4_address: 192.168.0.4
  reading-comprehension-ws:
    image: registry.gitlab.com/connorbutch/reading-comprehension
    restart: on-failure
    ports:
      - 8080:8080
    expose:
      - 8080
volumes:
  my-db:

For those unfamiliar with quarkus, it works similar to spring, in that it autowires/injects a datasource based on values set in the application.properties. You can find this file here: https://gitlab.com/connorbutch/reading-comprehension/-/blob/9-list-all-assessments/reading-comprehension-server-quarkus-impl/src/main/resources/application.properties, and I've also included the source below:

#Adding reflection config for generated models as well as properties file containing sql -> https://quarkus.io/guides/writing-native-applications-tips
quarkus.native.additional-build-args =-H:ReflectionConfigurationFiles=reflection-config.json, -H:ResourceConfigurationFiles=resources-config.json

#database (mysql) stuff -> https://quarkus.io/guides/datasource
quarkus.datasource.db-kind=mysql
quarkus.datasource.username=root
quarkus.datasource.password=password
quarkus.datasource.jdbc.url=jdbc:mysql://192.168.0.4:3306/rc
#the below doesn't seem to execute on startup, which makes me think it can't connect at all
#quarkus.datasource.new-connection-sql=CREATE DATABASE IF NOT EXISTS RC

To run the application, use this file: https://gitlab.com/connorbutch/reading-comprehension/-/blob/9-list-all-assessments/run-it.sh

Any ideas on what to look at (application.yaml, build.gradle, etc)? Thanks, Connor [1]: https://i.stack.imgur.com/5Hmry.jpg [2]: https://i.stack.imgur.com/9nHip.png

1

1 Answers

-1
votes

Your service is unable to connect to your database, try adding the below to your service 'reading-comprehension-ws':

environment:
  quarkus.datasource.url: "jdbc:mysql://db:3306/{your-schema name}"

You need to replace {your-schema name} with your real schema name.

Since they are running in same docker-compose network, your service should be able to lookup your DB by service name.