gnodet opened a new pull request, #30147:
URL: https://github.com/apache/camel/pull/30147

   ## Summary
   
   Stop the JPA consumer before the final assertion block in 
`JpaWithNamedQueryTest` (and
   its subclasses) to eliminate a deadlock that could block CI indefinitely.
   
   ## Root Cause
   
   A classic lock-ordering deadlock between two threads competing for OpenJPA 
internal locks:
   
   **Main test thread** (final `transactionTemplate` assertion block):
   - Holds `StateManagerImpl` lock (via entity field access: `row.getStep()` →
     `row.toString()` → `MultiSteps.getId()` → OpenJPA 
`StateManagerImpl.beforeAccessField`)
   - Waits for `BrokerImpl` lock
   
   **JPA consumer polling thread** (next scheduled `poll()` after the first 
message was processed):
   - Holds `BrokerImpl` lock (in `BrokerImpl.detachAll()` during 
`entityManager.clear()`)
   - Waits for `StateManagerImpl` lock
   
   Both locks are `ReentrantLock` instances in OpenJPA — the JVM deadlock 
detector can
   identify this but cannot resolve it. The existing workaround in CAMEL-23323 
added
   a 10-minute Surefire timeout but did not address the root cause.
   
   ## Fix
   
   After the first `await()` confirms the consumer has fired and 
`receivedExchange` has been
   captured as a defensive copy (`e.copy()`), call 
`ServiceHelper.stopService(consumer)`.
   
   This stops the consumer's scheduled polling thread before the test thread 
enters the
   final assertion block that accesses entity fields. With no concurrent 
`entityManager.clear()`
   calls possible, the OpenJPA lock contention cannot occur.
   
   The fix is in the base class and therefore covers all four affected tests:
   - `JpaWithNamedQueryTest`
   - `JpaWithQueryTest`
   - `JpaWithNativeQueryTest`
   - `JpaWithNativeQueryWithResultClassTest`
   
   `tearDown()` already calls `ServiceHelper.stopService(consumer, template)`, 
which is
   idempotent for an already-stopped consumer.
   
   ## Tests
   
   The four affected JPA query tests all pass locally with this change.
   
   Fixes CAMEL-23360
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to