Quantcast
Channel: Active questions tagged propagation - Stack Overflow
Viewing all articles
Browse latest Browse all 52

Issue with Multiple Asynchronous Database Calls Resulting in ResultSet Closure Exception

$
0
0

I'm facing an issue with multiple asynchronous database calls in my Java application, which is using Hibernate and DB2 as the database. The problem seems to be related to context propagation or possibly the way the async operations are being handled. Here's a simplified version of the method where the issue occurs:

private final ManagedExecutor managedExecutor = ManagedExecutor.builder()    .propagated(ThreadContext.CDI)    .build();public ProcessedData fetchProcessedData(String processId, String userId) {try {    DataRecord dataRecord = dataRecordRepository.find("processId = ?1 AND orgId = ?2",            processId, authTokenProvider.getOrgId()).firstResult();    if (dataRecord == null) {        throw new DataNotFoundException("Data record not found");    }    CompletableFuture<List<ActionRecord>> actionsFuture = taskExecutor.supplyAsync(            () -> actionRepository.find("processId = ?1",                    Sort.by("actionTimestamp").ascending(),                    processId).list()    );    CompletableFuture<List<FileRecord>> filesFuture = taskExecutor.supplyAsync(            () -> fileRepository.find("processId = ?1", processId).list()    );    CompletableFuture<UserProfile> userProfileFuture = taskExecutor.supplyAsync(            () -> fetchUserProfile(userId)    );    return DataMapper.mapToProcessedData(            processId,            actionsFuture.join(),            filesFuture.join(),            userProfileFuture.join(),            dataRecord.getAssignedAgent()    );} catch (Exception ex) {    System.err.println("An error occurred while fetching the processed data: " + ex.getMessage());    ex.printStackTrace();    throw new RuntimeException("Failed to fetch processed data", ex);}

It works fine when there is only a single async call to the database (and other async tasks but DB) but when there are multiple async DB calls (as shown above), I encounter the following exceptions:

Caused by: org.hibernate.sql.exec.ExecutionException: A problem occurred in the SQL executor: Error advancing (next) ResultSet position [[jcc][t4][10120][10898][4.32.28] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null]Caused by: org.hibernate.exception.GenericJDBCException: Error advancing (next) ResultSet position [[jcc][t4][10120][10898][4.32.28] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null] [n/a]Caused by: com.ibm.db2.jcc.am.SqlException: [jcc][t4][10120][10898][4.32.28] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null

From what I understand, the issue might be related to the context propagation or possibly how the async operations are interacting with the database. However, I'm not entirely sure what's causing this

Any advice or guidance would be greatly appreciated!


Viewing all articles
Browse latest Browse all 52

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>