Skip to content

TCP connection error handling logic #114

Description

@sansmoraxz

I am trying to understand the link recovery mechanism. So for this, I am using a tcp modbus simulator. Sometimes I restart the server, or disconnect/ reconnect the simulator into the network.

So here's what I have observed. io.EOF is being propagated into the clients.

So, is connection recovery a built in feature of the library, or should be handle those from client side (by dropping the previous client).

Going deeper into the codebase, I see this:

modbus/tcpclient.go

Lines 321 to 328 in 99e372e

} else if (err != io.EOF && err != io.ErrUnexpectedEOF) ||
mb.LinkRecoveryTimeout == 0 || time.Until(recoveryDeadline) < 0 {
return
}
// any other error, but recovery deadline isn't reached yet - close and retry
res = readResultCloseRetry
return
}

The condition (err != io.EOF && err != io.ErrUnexpectedEOF) check feels convoluted. Also, readResultCloseRetry is not used anywhere else other than this assignment.

Feels like a logic bug, but I am not sure of the intention here too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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