Skip to content

Fix Paho client cleanup after failed startup - #25508

Open
nkokitkar wants to merge 1 commit into
apache:mainfrom
nkokitkar:nkokitkar-microsoft-fix-paho-startup-cleanup
Open

Fix Paho client cleanup after failed startup#25508
nkokitkar wants to merge 1 commit into
apache:mainfrom
nkokitkar:nkokitkar-microsoft-fix-paho-startup-cleanup

Conversation

@nkokitkar

Copy link
Copy Markdown
Contributor

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

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

AI-assisted contributions

  • If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., Co-authored-by trailers) and the PR description identifies the AI tool used.

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 davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catchThrowableOfType(callable, type) overload was deprecated in AssertJ 3.22+. Consider using the swapped parameter order:

Suggested change
MqttException thrown = catchThrowableOfType(MqttException.class, consumer::doStart);

This applies to the other catchThrowableOfType calls in this file and in PahoMqtt5ConsumerLifecycleTest as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants