Skip to content

Modbus client race condition in rtu connections #685

@sansmoraxz

Description

@sansmoraxz

🐞 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:

func (info *ConnectionInfo) String() string {
if info.Protocol == ProtocolTCP {
return fmt.Sprintf("%s:%s:%d:%d", info.Protocol, info.Address, info.Port, info.UnitID)
}
return fmt.Sprintf("%s:%s:%d:%d:%d:%d:%d:%s", info.Protocol, info.Address, info.Port, info.UnitID, info.BaudRate, info.DataBits, info.StopBits, info.Parity)
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions