Not able to access RDS in my spring boot application inside docker - spring

I wanted to dockerize my spring boot application. I used
docker build -t <Name> .
to build my project and then try to run it. But my spring boot application gives Communication link failure and is not able to connect to the rds database. I have setup database url correctly in properties file and my application is inside same VPC as the RDS. My docker file is:
FROM maven:3.5.2-jdk-8-alpine AS MAVEN_TOOL_CHAIN
COPY pom.xml /tmp/
WORKDIR /tmp/
RUN mvn verify clean --fail-never
COPY src /tmp/src/
RUN mvn package -DskipTests
FROM tomcat:8.0.51-jre8-alpine
COPY --from=MAVEN_TOOL_CHAIN /tmp/target/<ProjectName>.war $CATALINA_HOME/webapps/<ProjectName>.war
COPY ./conf/* $CATALINA_HOME/conf/
CMD ["catalina.sh","run"]
Stack trace of the error im getting is below:
2019-03-14 14:17:03.400 WARN 1 --- [pool-3-thread-1] o.h.e.j.s.SqlExceptionHelper : SQL Error: 0, SQLState: 08S01
2019-03-14 14:17:03.400 ERROR 1 --- [pool-3-thread-1] o.h.e.j.s.SqlExceptionHelper : Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
2019-03-14 14:17:03.400 INFO 1 --- [pool-3-thread-1] c.d.c.s.c.CampaignAnalyticsService : error in updating analytics Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
2019-03-14 14:17:03.400 INFO 1 --- [pool-3-thread-1] c.d.c.s.c.CampaignAnalyticsService : [543, Send, Announcement, -, Sukhna:, Run, for, fun]
2019-03-14 14:17:03.401 INFO 1 --- [pool-3-thread-1] c.z.h.HikariDataSource : HikariPool-1 - Starting...
2019-03-14 14:17:04.402 ERROR 1 --- [pool-3-thread-1] c.z.h.p.HikariPool : HikariPool-1 - Exception during pool initialization.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
I use the following command to run my image :
docker run -p 8081:8000 <Name>

Related

Spring Boot AWS logging level

I have several Spring Boot micro services that connect to Config Server and Eureka. All are running inside Docker container in ECS. They are very chatty and I would like to eliminate the non-critical messages.
2023-01-06 16:42:03.426 WARN 1 --- [tbeatExecutor-0]
c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with
message... 2023-01-06 16:43:28.082 INFO 1 --- [trap-executor-0]
c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via
configuration... 2023-01-06 16:50:03.679 INFO 1 --- [freshExecutor-0]
o.apache.http.impl.execchain.RetryExec... 2023-01-06 16:42:03.426 INFO
1 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient...
And each service has its application.properties file with the following:
logging.level.org.springframework.cloud.netflix.eureka.http=FATAL
logging.level.com.netflix.discovery=FATAL
logging.level.com.netflix.discovery.shared.resolver.aws = ERROR
logging.level.com.netflix.eureka.registry = ERROR
logging.level.org.springframework.web.servlet = FATAL
logging.level.org.hibernate = ERROR logging.level.com.zaxxer.hikari =
ERROR logging.level.org.apache.tomcat=ERROR
logging.level.org.apache.catalina=ERROR
But the messages continue to show up in the log files. I don't get why this is, since those messages are INFO and WARN.
In order to disable below error messages use the config below
logging.level.com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient=error
also in your config I see logging.level.org.springframework.web.servlet = FATAL logging.level.org.hibernate = this looks wrong, every line should have one gorup name = something, then new line.

Spring boot crashes randomly without errors

I have a Spring boot application in version 2.1.2.RELEASE. Once a month or few weeks application crashes without any specific information in logs.
Server where app is deploy is CentOS ver 7, app is launched by a systemd service.
Tried analysing heap dump, no luck, checked logs of postgres, tomcat etc. nothing there.
Stacktrace:
INFO ;read-5;523575402;2019-08-07 17:27:24,714;o.s.i.e.EventDrivenConsumer; Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
INFO ;read-5;523575418;2019-08-07 17:27:24,730;o.s.i.c.PublishSubscribeChannel; Channel 'application.errorChannel' has 0 subscriber(s).
INFO ;read-5;523575418;2019-08-07 17:27:24,730;o.s.i.e.EventDrivenConsumer; stopped _org.springframework.integration.errorLogger
INFO ;read-5;523575502;2019-08-07 17:27:24,814;o.s.s.c.ThreadPoolTaskScheduler; Shutting down ExecutorService 'taskScheduler'
INFO ;read-5;523575541;2019-08-07 17:27:24,853;o.s.s.c.ThreadPoolTaskExecutor; Shutting down ExecutorService 'applicationTaskExecutor'
INFO ;read-5;523575572;2019-08-07 17:27:24,884;o.s.o.j.LocalContainerEntityManagerFactoryBean; Closing JPA EntityManagerFactory for persistence unit 'default'
INFO ;read-5;523575596;2019-08-07 17:27:24,908;c.z.h.HikariDataSource; HikariPool-1 - Shutdown initiated...
INFO ;read-5;523575631;2019-08-07 17:27:24,943;c.z.h.HikariDataSource; HikariPool-1 - Shutdown completed.
WARN ;exec-8;523575668;2019-08-07 17:27:24,980;c.z.h.p.ProxyConnection; HikariPool-1 - Connection org.postgresql.jdbc.PgConnection#6ff70ea8 marked as broken because of SQLSTATE(08006), ErrorCode(0)
org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:335)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:106)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2173)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1936)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898)
WARN ;exec-6;523575677;2019-08-07 17:27:24,989;c.z.h.p.ProxyConnection; HikariPool-1 - Connection org.postgresql.jdbc.PgConnection#71c6647 marked as broken because of SQLSTATE(08006), ErrorCode(0)
org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:335)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:106)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
WARN ;exec-8;523575721;2019-08-07 17:27:25,033;o.h.e.j.s.SqlExceptionHelper; SQL Error: 0, SQLState: 08006
WARN ;exec-6;523575721;2019-08-07 17:27:25,033;o.h.e.j.s.SqlExceptionHelper; SQL Error: 0, SQLState: 08006
ERROR;exec-8;523575721;2019-08-07 17:27:25,033;o.h.e.j.s.SqlExceptionHelper; An I/O error occurred while sending to the backend.
ERROR;exec-6;523575721;2019-08-07 17:27:25,033;o.h.e.j.s.SqlExceptionHelper; An I/O error occurred while sending to the backend.
INFO ;exec-6;523575885;2019-08-07 17:27:25,197;o.h.e.i.DefaultLoadEventListener; HHH000327: Error performing load command : org.hibernate.exception.JDBCConnectionException: could not extract ResultSet
org.hibernate.exception.JDBCConnectionException: could not extract ResultSet
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
Has anyone got idea how can I what might be going on? Last crash was 3, 4 weeks before that.
That type of error happens when the database connection has been lost, which in turn can happen for a whole number of reasons, the most simple one being that it's being restarted after system updates or as part of a scheduled operation.
HikariCP should be able to recover according to the following link (provided that your HikariCP version is recent enough):
https://github.com/brettwooldridge/HikariCP/wiki/Rapid-Recovery
You may need to configure some properties in your pool. The full list of properties is available here:
https://github.com/brettwooldridge/HikariCP
I recommend you configure the following in HikariCP:
connectionTestQuery: will test the connection periodically, dropping dead connections. Use it in conjunction with socketTimeout in your PostgreSQL connection string
leakDetectionThreshold: will help with applications having connection leaks

The Tomcat connector configured to listen on port 28081 failed to start in the linux

I'm doing a spring boot project , and this project can run successfully in the eclipse and war use cmd. However it failed to start in the linux environment.
I have used netstat -ano | grep 28081 , the port is not in use.
2019-04-02 05:49:50.628 WARN 25548 --- [localhost-startStop-1] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [cluster-ClusterId{value='5ca33035b36bfd63cc6ff647', description='null'}-lswsstpfdb3u.nam.nsroot.net:28120] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.waitForSignalOrTimeout(DefaultServerMonitor.java:226)
com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.waitForNext(DefaultServerMonitor.java:207)
com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:154)
java.lang.Thread.run(Thread.java:745)
2019-04-02 05:49:50.640 INFO 25548 --- [defaultTaskExecutor-4] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-04-02 05:49:50.646 ERROR 25548 --- [main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Tomcat connector configured to listen on port 28081 failed to start. The port may already be in use or the connector may be misconfigured.
Action:
Verify the connector's configuration, identify and stop any process that's listening on port 28081, or configure this application to listen on another port.
Local war instruction is :
C:\tmp\jdk1.8.0_31_x64\jre\bin\java -DaEnv=UAT -Denv=UAT -Da.domainName=pfDomain -Drealtime.nodeName=Node1 -jar C:\aServices.war -Djava.protocol.handler.pkgs=javax.net.ssl -Djavax.net.ssl.keyStore=C:\SSL-keystore.UAT.jks -Djavax.net.ssl.trustStore=C:\SSLTrust.UAT.jks
The application can start successfully.
In the application.properties file , the ssl location is wrong , it should like this :
server.ssl.key-store=/opt/a/etc/SSL-keystore.jks
server.ssl.trust-sotre=/opt/a/etc/certs/SSLTrust.jks

JMS ActiveMQ SpringBoot .FailoverTransport

iam trying to connected to remote broker url in activeMQ (activemq installed in unix vm)
iam able to connect from browser from my laptop.
while running springboot iam getting this error
--- [ActiveMQ Task-1] o.a.a.t.failover.FailoverTransport : Failed to connect to [tcp://http://199.247.18.11:61616] after: 8 attempt(s) continuing to retry.
what could be the issue?
Please remove https:// from your connection string. Port 61616 is expecting JMS connections.
Your connection string should be tcp://199.247.18.11:61616 or something similar. There is a rest API that (I think) goes through the built in HTTP server but it's not going to listen on 61616 and it's going to have a much longer URL. Something like
http://admin:admin#localhost:8161/api/message?destination=queue://myqueue
still issue
yml file
activemq:
broker-url: failover:(tcp://http://199.247.18.11:61616)?initialReconnectDelay=1000&maxReconnectDelay=60000&warnAfterReconnectAttempts=2
error:
2018-05-01 07:41:51.312 WARN 6560 --- [ActiveMQ Task-1] o.a.a.t.failover.FailoverTransport : Failed to connect to [tcp://http://199.247.18.11:61616] after: 2 attempt(s) continuing to retry.

PostgreSQL hibernate and spring

I'm trying to use Hibernate with Spring and PostgreSQL, but I have lots of errors like:
org.postgresql.Driver : Connection error
ERROR 3424 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
I have put postgreSQL.Driver in my libs but nothing to do error say there.
Edit:
2018-03-19 15:54:53.660 INFO 7640 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-03-19 15:54:54.664 WARN 7640 --- [ main] unknown.jul.logger : ConnectException occurred while connecting to localhost:5432`
`at com.ttmik.back.MainKt.main(main.kt:19) ~[classes/:na]
2018-03-19 15:54:54.675 ERROR 7640 --- [ main] org.postgresql.Driver : Connection error:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Check if your PostgreSQL can be reached by using telnet. If you get something like:
telnet localhost 5432
Connecting To localhost...
Could not open connection to the host, on port 5432: Connection failed
then most likely need to change listen_addresses to * in postgresql.conf file as per this answer on serverfault.

Resources