Fix Paho client cleanup after failed startup - #25508
Conversation
Force-close internally owned MQTT v3 and v5 clients after startup or shutdown failures while preserving shared-client ownership. Keep the primary lifecycle exception and suppress any close failure. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
davsclaus
left a comment
There was a problem hiding this comment.
Claude Code on behalf of davsclaus
Thanks for the contribution — the client leak on startup failure is a real bug and the fix pattern (try-catch-finally with addSuppressed) is well done. Good test coverage too.
Findings
1. Missing JIRA ticket (Medium)
Per project conventions, bug fixes should have a JIRA issue filed. This is a non-trivial fix across 6 files — please create a JIRA ticket and reference it in the PR title/commits (e.g. CAMEL-XXXXX: Fix Paho client cleanup after failed startup).
2. Producer classes have the same bug (Medium)
PahoProducer and PahoMqtt5Producer have the identical lifecycle leak — if client.connect() throws in doStart(), the MqttClient instance leaks its thread pool and file-based persistence. Was the scope intentionally limited to consumers? If so, please file a follow-up JIRA to track the producer fix.
3. catchThrowableOfType parameter order (Low)
The catchThrowableOfType(callable, type) two-argument overload was deprecated in AssertJ 3.22+ in favor of catchThrowableOfType(type, callable) (swapped parameter order). Consider using the non-deprecated form or assertThatThrownBy(...) instead.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
| assertThat(thrown).isSameAs(connectException); | ||
| verify(client).close(true); | ||
| } | ||
|
|
There was a problem hiding this comment.
The catchThrowableOfType(callable, type) overload was deprecated in AssertJ 3.22+. Consider using the swapped parameter order:
| MqttException thrown = catchThrowableOfType(MqttException.class, consumer::doStart); |
This applies to the other catchThrowableOfType calls in this file and in PahoMqtt5ConsumerLifecycleTest as well.
Review (Grok + Bugbot)AI-generated review on behalf of Omar Atie Reviewed PR #25508 — Fix Paho client cleanup after failed startup ( SummaryThis fixes a real resource leak in The fix is sound:
Bugbot findingsNo critical bugs in the consumer fixThe lifecycle logic is correct. Shared clients are never closed; owned clients are always closed in Medium — same leak still exists in producers
Medium — missing JIRA + incomplete PR template
Per Camel conventions, non-trivial bug fixes need a JIRA reference. Low — AssertJ deprecated APITests use catchThrowableOfType(MqttException.class, consumer::doStart)Or Low — missing test for subscribe failure on startTests cover connect failure and stop paths, but not subscribe/callback failure after a successful connect. Code path should still cleanup (same catch block), but an explicit test would lock that in. Low — behavior change on normal stop (intentional improvement)Old Grok assessment
VerdictApprove with minor changes requested (not blocking on code logic):
The consumer lifecycle fix itself looks ready to merge once process items are addressed. |
Force-close internally owned MQTT v3 and v5 clients after startup or shutdown failures while preserving shared-client ownership. Keep the primary lifecycle exception and suppress any close failure.
Description
Target
mainbranch)Tracking
Apache Camel coding standards and style
mvn clean install -DskipTestslocally from root folder and I have committed all auto-generated changes.AI-assisted contributions
Co-authored-bytrailers) and the PR description identifies the AI tool used.