Skip to content

fix: Serial connections race condition#693

Open
sansmoraxz wants to merge 2 commits intoedgexfoundry:mainfrom
sansmoraxz:fix/rtu-race-conditions
Open

fix: Serial connections race condition#693
sansmoraxz wants to merge 2 commits intoedgexfoundry:mainfrom
sansmoraxz:fix/rtu-race-conditions

Conversation

@sansmoraxz
Copy link
Copy Markdown
Contributor

@sansmoraxz sansmoraxz commented Dec 21, 2025

Ensure devices registered on serial share the same client

Fixes: #685

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/device-modbus-go/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?) NA

Testing Instructions

Test cases. And against real hardware on same serial port.

New Dependency Instructions (If applicable)

NA

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Dec 21, 2025

Codecov Report

❌ Patch coverage is 14.28571% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.26%. Comparing base (81a5ed9) to head (a5f73a6).

Files with missing lines Patch % Lines
internal/driver/modbusclient.go 0.00% 8 Missing ⚠️
internal/driver/driver.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #693      +/-   ##
==========================================
- Coverage   45.80%   45.26%   -0.55%     
==========================================
  Files           7        7              
  Lines         834      844      +10     
==========================================
  Hits          382      382              
- Misses        400      410      +10     
  Partials       52       52              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Souyama <souyamadebnath@gmail.com>
@sansmoraxz sansmoraxz force-pushed the fix/rtu-race-conditions branch from 674d363 to ec2c536 Compare December 21, 2025 18:29
Signed-off-by: Souyama <souyamadebnath@gmail.com>
@sansmoraxz sansmoraxz force-pushed the fix/rtu-race-conditions branch from ec2c536 to a5f73a6 Compare December 21, 2025 18:31
@sansmoraxz
Copy link
Copy Markdown
Contributor Author

We should not be mixing baude rates, partity etc on the same port. Perhaps there can be a QOL improvement to bubble this up to the user when they are registering devices.

@sansmoraxz sansmoraxz marked this pull request as ready for review January 8, 2026 11:53
@cloudxxx8 cloudxxx8 requested a review from weichou1229 January 9, 2026 01:55
@weichou1229
Copy link
Copy Markdown
Member

@sansmoraxz Do you think the serial connection should be locked? Because the Modbus usually doesn't support multiple threads, the driver locks the command by address as shown below:

func (d *Driver) lockableAddress(info *ConnectionInfo) string {
var address string
if info.Protocol == ProtocolTCP {
address = fmt.Sprintf("%s:%d", info.Address, info.Port)
} else {
address = info.Address
}
return address

@sansmoraxz
Copy link
Copy Markdown
Contributor Author

It's quite odd, even with the above semaphore we were facing timeout issues with multiple devices.
^ Linked PR.

Not entirely sure what was happening then, might need to investigate more.

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.

Modbus client race condition in rtu connections

3 participants