CAMEL-24128: camel-jpa - Fix EntityManager leak in JpaPollingConsumer#24791
Conversation
… instead of createPreDeleteHandler() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
gnodet
left a comment
There was a problem hiding this comment.
Clean fix for an EntityManager leak — every JpaPollingConsumer.receive() call leaked an unclosed EM.
Note: This PR is stacked on PR #24790 (CAMEL-24129, the createPreDeleteHandler → getPreDeleteHandler fix). My review focuses on the CAMEL-24128 commit.
The bug: receive() calls getTargetEntityManager(null, ...) — passing null for the exchange. Inside JpaHelper.createEntityManager(), the null exchange check at line 104 skips:
- Storing the EM for reuse (line 106-107)
- Registering
JpaCloseEntityManagerOnCompletion(line 116) — the only cleanup path
So every successful receive() creates an EntityManager that is never closed.
The fix: Move Exchange exchange = getEndpoint().createExchange() before the getTargetEntityManager() call so the exchange is available to pass. Now createEntityManager() receives a non-null exchange, stores the EM, and registers the JpaCloseEntityManagerOnCompletion synchronization that closes it when the exchange completes.
The change is minimal — just reorder two statements and replace null with exchange. No new behavior, just enabling the existing cleanup mechanism.
Checklist:
- ✅ Minimal fix, enables the existing
JpaCloseEntityManagerOnCompletioncleanup - ✅ Consistent with how
JpaConsumer.poll()already passes the exchange togetTargetEntityManager() - ✅ Existing
JpaPollingConsumer*tests pass (4 tests per PR description) - ✅ CI pending (builds running)
Reviewed with Claude Code (claude-code/1.0) on behalf of gnodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 9 tested, 29 compile-only — current: 9 all testedMaveniverse Scalpel detected 38 affected modules (current approach: 9).
|
Summary
JpaPollingConsumer.receive()leaking anEntityManageron every successful callnullinstead of the exchange togetTargetEntityManager(), which skipped registeringJpaCloseEntityManagerOnCompletionon the exchangeTest plan
JpaPollingConsumer*tests pass (4 tests)Claude Code on behalf of davsclaus
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com