Failed to retrieve next task from task queue

0
Hello everyone ;)    I do get the following error regarding task queues and I am not sure why   The message of the error is    Failed to retrieve next task from task queue 'SGVirusScan.TQ_SaveWithAPIScan': An exception has occurred for the following request(s): InternalXPathTextGetRequest (depth = 0, amount = 1): //System.QueuedTask[QueueId=$queueId and Status='Idle' and ThreadId=empty and (StartAt<='[%CurrentDateTime%]' or StartAt=empty)]   The stacktrace is    com.mendix.connectionbus.ConnectionBusRuntimeException: An exception has occurred for the following request(s): InternalXPathTextGetRequest (depth = 0, amount = 1): //System.QueuedTask[QueueId=$queueId and Status='Idle' and ThreadId=empty and (StartAt<='[%CurrentDateTime%]' or StartAt=empty)] at com.mendix.connectionbus.RequestAnalyzer.doRequest(RequestAnalyzer.scala:35) Caused by: com.mendix.connectionbus.ConnectionBusRuntimeException: Connection is invalid, but it is subject of a transaction. at com.mendix.connectionbus.connections.jdbc.JdbcDataStore.closeConnectionImmediately(JdbcDataStore.scala:512) at com.mendix.connectionbus.connections.jdbc.JdbcDataStore.handleConnectionError(JdbcDataStore.scala:218) at com.mendix.connectionbus.connections.jdbc.JdbcDataStore.execRetrieveQueries(JdbcDataStore.scala:171) at com.mendix.connectionbus.connections.jdbc.JdbcDataStore.retrieve(JdbcDataStore.scala:141) at com.mendix.connectionbus.retrieve.QueryRequestExecutor.executeQueriesForLocal(QueryRequestExecutor.scala:102) at com.mendix.connectionbus.retrieve.QueryRequestExecutor.executeQueries(QueryRequestExecutor.scala:34) at com.mendix.connectionbus.retrieve.QueryRequestExecutor.execute(QueryRequestExecutor.scala:26) at com.mendix.connectionbus.retrieve.DataStoreCaller.$anonfun$processOqlGetRequest$1(DataStoreCaller.scala:36) at scala.Option.map(Option.scala:242) at com.mendix.connectionbus.retrieve.DataStoreCaller.processOqlGetRequest(DataStoreCaller.scala:32) at com.mendix.connectionbus.retrieve.DataStoreCaller.$anonfun$getResult$1(DataStoreCaller.scala:26) at scala.collection.StrictOptimizedIterableOps.flatMap(StrictOptimizedIterableOps.scala:118) at scala.collection.StrictOptimizedIterableOps.flatMap$(StrictOptimizedIterableOps.scala:105) at scala.collection.immutable.ArraySeq.flatMap(ArraySeq.scala:35) at com.mendix.connectionbus.retrieve.DataStoreCaller.getResult(DataStoreCaller.scala:26) at com.mendix.connectionbus.retrieve.GetRequestHandler.doOtherRequests(GetRequestHandler.scala:69) at com.mendix.connectionbus.retrieve.GetRequestHandler.doRequest(GetRequestHandler.scala:29) at com.mendix.connectionbus.RequestAnalyzer.doRequest(RequestAnalyzer.scala:30) at com.mendix.connectionbus.ConnectionBusImpl.doRequest(ConnectionBusImpl.scala:474) at com.mendix.modules.queue.TaskQueue.claimTasks(TaskQueue.scala:306) at com.mendix.modules.queue.TaskQueue.$anonfun$acquire$1(TaskQueue.scala:134) at com.mendix.logging.impl.LogManager.suppressLogMessagesInThreadBelow(LogManager.java:49) at com.mendix.modules.queue.TaskQueue.acquire(TaskQueue.scala:117) at com.mendix.modules.queue.TaskDispatcher.acquireTasks(TaskDispatcher.scala:183) at com.mendix.modules.queue.TaskDispatcher.poll(TaskDispatcher.scala:153) at com.mendix.modules.queue.TaskDispatcher.$anonfun$pollThread$1(TaskDispatcher.scala:45) at java.base/java.lang.Thread.run(Unknown Source)   This happens for multiple task queues that are running on my system. I am not sure why.    Thanks, Marcian :)
asked
1 answers
1

The error typically occurs when the Mendix runtime tries to retrieve a task from the queue but encounters a database connection issue. Specifically, the connection may have been closed or become invalid while still being part of an active transaction. This can happen due to:

  • Database connection timeouts or instability.
  • Long-running transactions that exceed connection pool limits.
  • Improper handling of queued tasks that leave connections open.

Recommended Fixes

  1. Upgrade Mendix Runtime and Queue ModuleIf you're using an older version of Mendix or the deprecated Queue module, upgrade to the latest Mendix version and use the built-in Task Queue feature introduced in Mendix 9.0.3

  2. Check Database Connection Pool SettingsEnsure your database connection pool is sized appropriately for the number of concurrent tasks. You may need to increase the pool size or reduce the number of parallel tasks.

  3. Avoid Long-Running Transactions in Queued MicroflowsReview the microflows executed by the task queue. Avoid long-running operations or nested loops that hold database connections for extended periods.

  4. Use Commit and EndTransaction WiselyMake sure that each queued task commits its changes and ends the transaction properly. Uncommitted changes or open transactions can cause connection issues.

  5. Enable Connection ValidationIn your database configuration, enable connection validation (e.g., validationQuery in JDBC) to ensure connections are alive before use.

  6. Monitor Logs and Database HealthUse Mendix logs and your database monitoring tools to track connection usage, timeouts, and errors. This can help pinpoint the exact cause.

If this issue persists across multiple queues, it may indicate a systemic problem with how tasks are managed or how the database is configured. 

answered