edgexfoundry / edgexfoundry/device-modbus-go
Modbus client race condition in rtu connections
- Dominant language
- Go
- Stars
- 120
- Forks
- 105
- PR merge metrics
- No merged PRs in 30d
Description
# 🐞 Bug Report
### Affected Services [**REQUIRED**]
The issue is located in: https://github.com/edgexfoundry/device-modbus-go
### Is this a regression?
Not as far as I am aware
### Description and Minimal Reproduction [**REQUIRED**]
Connect multiple devices in same serial port and make high frequency requests (still maintain < 3 requests per second) simultaneously (within 1 ms).
This is due to the mutex not considering the scenario of multiple slaves over the same connection.
For the mutex lock key here unitId should not be part of it:
https://github.com/edgexfoundry/device-modbus-go/blob/2c8c7f329682967ec1662179493059457ab078d2/internal/driver/config.go#L34-L39
IMO perhaps before each request set the unitId in the RTU connection. Also I don't think you can run via different baude rates in same connection.
## 🔥 Exception or Error
Serial timeouts occasionally happen.
## 🌍 Your Environment
**Deployment Environment:** Device connected via direct serial port in `/dev/ttyS1` and against RS485 USB adapter via `dev/ttyUSB0`
**EdgeX Version [**REQUIRED**]:** build code from main branch
**Anything else relevant?**
_Originally posted by @sansmoraxz in [#666](https://github.com/edgexfoundry/device-modbus-go/issues/666#issuecomment-3550994711)_
Contributor guide
Research direction
Start in internal/driver/config.go at lines 34-39, then reproduce with multiple devices sharing one serial port and simultaneous requests within 1 ms. Inspect how the mutex lock key handles unitId and how the RTU connection is configured. Done means the shared connection avoids occasional serial timeouts under the reported workload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100