-
Couldn't load subscription status.
- Fork 160
🐛 [Broker] LWT triggered by different node #4301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this 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())) { |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
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.
| 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())) { |
| 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."); |
Copilot
AI
Oct 10, 2025
There was a problem hiding this comment.
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.
| throw new ActiveMQSecurityException("Cannot get device connection info. Abort LWT sending."); | |
| throw new ActiveMQSecurityException("Cannot get device connection info. Abort LWT sending.", e); |
993b7d0 to
f82c3ef
Compare
Signed-off-by: riccardomodanese <[email protected]>
f82c3ef to
a736eb5
Compare
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