Unable to acquire lock on tasks - Cannot get a connection, pool error Timeout waiting for idle object

After app executes some scheduled tasks between 08.15 and 08.18 and then start a scheduled task to generate reports automatically I got a “Unable to acquire lock on tasks” followed by subsequently “Cannot get a connection, pool error Timeout waiting for idle object” errors

I’m using cuba platform version 7.2.18.
Main datasource is connected to a postgres database 9.6 engine
Also my second datasource is a MsSQL server 2016 13.0

Can please anyone give me a hint on this issue? App get’s unresponsive after this.

08:16:17.983 INFO  c.c.p.s.ZkAttendanceServiceBean         - No se encontro a persona con codigo: 113 de la fila 37839
08:16:17.988 INFO  c.c.p.s.ZkAttendanceServiceBean         - Total codigo de personas no encontradas: 1. Operacion de commit cancelada.
08:16:18.020 INFO  c.c.p.s.ZkAttendanceServiceBean         - Finalizando Importacion ZK zk.bv.01
08:16:18.020 INFO  c.c.p.s.ZkAttendanceServiceBean         - Iniciado Importacion ZK zk.bv.02
08:16:26.090 INFO  c.c.p.s.ZkAttendanceServiceBean         - Finalizando Importacion ZK zk.bv.02
08:16:26.090 INFO  c.c.p.s.ZkAttendanceServiceBean         - Iniciado Importacion ZK zk.bv.03
08:16:29.835 INFO  c.c.p.s.ZkAttendanceServiceBean         - Finalizando Importacion ZK zk.bv.03
08:16:29.835 INFO  c.c.p.s.ZkAttendanceServiceBean         - Iniciado Importacion ZK zk.bv.04
08:16:30.860 INFO  c.c.p.s.ZkAttendanceServiceBean         - Finalizando Importacion ZK zk.bv.04
08:16:30.860 INFO  c.c.p.s.CastAttendanceServiceBean       - Iniciando importacion Cast
08:16:40.365 INFO  c.c.p.s.CastAttendanceServiceBean       - Finalizando importacion Cast
08:16:40.365 INFO  c.c.p.s.AttendanceDailyServiceBean      - Iniciando Calculo de Marcaciones Diarias
08:16:40.365 INFO  c.c.p.s.AttendanceDailyServiceBean      - Borrando Duplicados Attendance
08:18:04.582 INFO  c.c.p.s.AttendanceDailyServiceBean      - Borrando Duplicados Attendance
08:18:05.356 INFO  c.c.p.s.AttendanceDailyServiceBean      - Borrando Duplicados AttendanceDaily
08:18:05.456 INFO  c.c.p.s.AttendanceDailyServiceBean      - Finalizando Calculo de Marcaciones Diarias
08:20:21.668 INFO  c.h.c.c.a.s.DbBasedCoordinator          - Unable to acquire lock on tasks
08:20:30.790 ERROR c.h.cuba.core.sys.ServiceInterceptor    - Exception:
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.19-cuba): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Cannot get a connection, pool error Timeout waiting for idle object

Hi,
CUBA application, like most Spring applications, connect to the database through connection pool. Connection pool size is limited and pre-configured via settings.

This error message means that all connections from the pool have been taken and haven’t been returned yet, so a new request cannot obtain a DB connection from the pool for working with data.

Usually this is a sign of:

  • database overloading, because of it normal database activity is slowed down a lot
  • or DB connection leak (someone starts transaction but doesn’t close them)

thanks @albudarov

I was heavilly using datamanager to read and write within a “for” statement. I will give it a try and use a single transaction and then commit and see if that fixes it.