Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@riccardomodanese
Copy link
Contributor

Brief description of the PR.
Fix the device disconnect/missing handling to avoid events creation or connection state updates if the node is not the owner of the connection.

Related Issue
none

Description of the solution adopted
see brief description

Screenshots
none

Any side note on the changes made
none

@riccardomodanese riccardomodanese added the Bug This is a bug or an unexpected behaviour. Fix it! label Oct 10, 2025
@codecov-commenter
Copy link

codecov-commenter commented Oct 10, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...a/broker/artemis/plugin/security/ServerPlugin.java 0.00% 9 Missing ⚠️
...entication/authentication/AuthenticationLogic.java 0.00% 2 Missing ⚠️
...cation/authentication/UserAuthenticationLogic.java 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes Last Will and Testament (LWT) handling in a multi-node environment to prevent events and connection state updates when a device is not owned by the current node.

  • Modified disconnect logic to only consider device ownership when determining if events should be fired
  • Added validation to ensure LWT messages are only processed by the node that owns the device connection
  • Refactored topic suffix constant and reused DeviceConnectionService instance

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
UserAuthenticationLogic.java Updated disconnect method to remove missing state check from conditions and simplify return logic
ServerPlugin.java Added device ownership validation for LWT processing and refactored service usage

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

sessionContext.setMissing(true);
try {
DeviceConnection deviceConnection = deviceConnectionService.findByClientId(sessionContext.getScopeId(), sessionContext.getClientId());
if (deviceConnection == null || !sessionContext.getBrokerHost().equals(deviceConnection.getServerIp())) {
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

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

The error message 'Device connected to another node' is misleading when deviceConnection is null. Consider using different messages: 'Device connection not found' when null, and 'Device connected to another node' when serverIp differs.

Suggested change
if (deviceConnection == null || !sessionContext.getBrokerHost().equals(deviceConnection.getServerIp())) {
if (deviceConnection == null) {
throw new ActiveMQSecurityException("Device connection not found. Abort LWT sending.");
}
if (!sessionContext.getBrokerHost().equals(deviceConnection.getServerIp())) {

Copilot uses AI. Check for mistakes.
throw new ActiveMQSecurityException("Device connected to another node. Abort LWT sending.");
}
} catch (KapuaException e) {
throw new ActiveMQSecurityException("Cannot get device connection info. Abort LWT sending.");
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

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

The error message should include the underlying exception details for better debugging. Consider logging the original exception or including its message in the thrown exception.

Suggested change
throw new ActiveMQSecurityException("Cannot get device connection info. Abort LWT sending.");
throw new ActiveMQSecurityException("Cannot get device connection info. Abort LWT sending.", e);

Copilot uses AI. Check for mistakes.
@riccardomodanese riccardomodanese force-pushed the fix-lwt_triggered_by_different_node branch from 993b7d0 to f82c3ef Compare October 14, 2025 07:26
@riccardomodanese riccardomodanese force-pushed the fix-lwt_triggered_by_different_node branch from f82c3ef to a736eb5 Compare October 15, 2025 12:50
@Coduz Coduz changed the title :fix: lwt triggered by different node 🐛 [Broker] LWT triggered by different node Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug This is a bug or an unexpected behaviour. Fix it!

Projects

Development

Successfully merging this pull request may close these issues.

3 participants