HikariPool-1 - Connection is not available -webclient - spring

I have some client class to external data provider.
In this class, I'm using webclient reactive client and crud repository.
Webclient uses repo to save responses from client (business requirement). For instance in onError, onStatus etc methods uses this repository. We performed load tests and it's working well.
The problem is when external API is not working and we're retrying couple of times (exponential backoff). Then I get:
HikariPool-1 - Connection is not available, request timed out after 30005ms
org.springframework.dao.DataAccessResourceFailureException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
So it seems like webclient is keeping connection while retrying for 30 seconds and we're running out of connections. Extending connection pool size is not the way I want to fix that.
Is there any way to release connection while webclient is jsut waiting for another retry and so on?

Related

Closing connections in Spring DATA jpa

I am using spring data jpa and hikari connection pooling. In repository file, I am using methods to connect to database. I would like to know how and where to close the database connections.
Repository
public interface abc extends JPARepository<abc, int>{
List<abc> findById(int id);}
Any help on how to close the connections and where(service layer or repository) would be really appreciated
`
With Connection Pooling, using the framework, The task of creating a connection before each operation and closing the connection after the operation is now taken from the programmer and transferred to the Spring Context:-
The application requests a connection from the connection pool.
If an unused connection exists, it is returned by the pool; otherwise, the pool creates a new connection.
The application sends a query to the Hybrid Data Pipeline connectivity service.
The application obtains query results.
The application displays the result to the end-user.
The application closes the connection, which returns the connection to the pool.
Note: The application calls the close() method, which allows the connection to remain open. The pool receives the notification of the close request.

Spring mongo driver connection pool close error

I have spring webflux/reactive server utilizing a singleton mongo database instance running on the same machine. Now, I have an rest endpoint in the server which triggers an external etl(python script using pymongo connection) on the db. But it then leads to pool close error on my spring server, and any subsequent database operations from the server fails.
2020-02-16T01:25:58.320+0530 [QUIET] [system.out] 2020-02-16 01:25:58.321 INFO 93553 --- [extShutdownHook] org.mongodb.driver.connection : Closed connection [connectionId{localValue:3, serverValue:133}] to localhost:27017 because the pool has been closed.
My etl runs for 10 secs, but mongo driver never reconnects after connection is closed from the pymongo side.
I tried mongodb configuration flags, but failed, don't know if there is a way. I am also willing to reconnect to mongodb on every rest call to avoid this, but any ideas/suggestions there.
I was hoping mongo_client should provide onClose() function, for the application to handle disconnections, but could not find any such handler.

Spring 5 JMS clientID=myapp.Topic was already set into another connection

I am using Spring Boot 2.2.1 (w/ Spring 5) to kick off my server with Spring JmsTemplate (HornetQ) connections. Every ~10s an ERROR is logged,
2020-01-17 18:00:49,091 [DefaultMessageListenerContainer-1] ERROR listener.DefaultMessageListenerContainer - Could not refresh JMS Connection for destination 'a.Topic' - retrying using FixedBackOff{interval=5000, currentAttempts=2, maxAttempts=unlimited}. Cause: clientID=myapp.Topic was already set into another connection
Did I accidentally create another client using the same id and compete for the connection/topic? Or something else I am not aware of.
Did I accidentally create another client using the same id and compete for the connection/topic?
Yes. According to the error message you're receiving you did.

Unable to acquire JDBC Connection in SpringBoot app

I have a Microservices‑Based Application, each Microservice is a SpringBoot 2.0.3.RELEASE app., but after my 4rth Microservices launched I have this error:
Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
..
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
I would like to know how to reduce the maximumPoolSize or if there is a way to know maximumPoolSize because I have't seen anything related when the app starts
You can set the maximum pool size of the JDBC connections in your application.properties file like:
spring.datasource.hikari.maximum-pool-size=5

JUnit - Oracle Database and StaleConnections

I was wondering is there any way in Java to force a stale connection?
We have some logic that determines if a sqlexception received is actually a Stale Connection - if it is we try and reconnect to the database.
I could not find any objects that could be mocked (using EasyMock or Powermock) in order to similulate a stale connection so I was there any properties we can set on the connection cache to expire a connection?

Resources