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.
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.