I found a deadlock in my system, but my attempts at getting rid of it failed.
There's this endpoint that is firing 3 or more requests to the DB, so when there's enough requests fo my endpoint fired simultaneously, the threads are locking each other, and the service is dead.
I tried to solve this by getting my endpoint to reuse its connection by annotating the first method call at controller-level with @Transactional.
This doesn't work though, the first request is still trying to get its own connection from the pool.
I used a TransactionManagerConfig.java for the configuration
@Configuration
public class TransactionManagerConfig {
@Bean(name ="oracleDataSourceTransactionManager", "transactionManager")
@Profile("!test")
@Primary
public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource){
return new DataSourceTransactionManager(dataSource);}
The method talking to the Database is called from a RestController, so I tried to use a @Transactional annotation at the controller level:
@RestController
@RequestMapping(value ={"/customer", "/agent", produces = {"application/json"})
@Transactional
public class UserController extends BaseController {
further down the calling stack, I'm getting a Customer number from the DB:
public interface UserRegistrationRepository extends JpaRepository<UserRegistration, Long>{
@Query(value = "SELECT CUSTOMER_NO FROM CUSTOMERS WHERE PK_USER =?1", nativeQuery = true)
Long getCustomerNumber(Long userId);
...
For some reason this is trying to get a new Transaction, causing a deadlock, if my connection pool runs out of connections.