grid-x / modbus

BSD 3-Clause "New" or "Revised" License
78 stars 26 forks source link

Handling network errors #90

Closed andig closed 1 month ago

andig commented 1 month ago

One of our users reports intermittent write: broken pipe errors. Unfortunately, errors are not resolved without restarting the application (i.e. forcing a new network connection). Looking at https://github.com/grid-x/modbus/blob/master/tcpclient.go we seem to return on error, but never close the connection. It seems to defeat reconnecting since conn will never be nil.

If this hunch is right: how should broken network connections be handled? Would it make sense to force-close the connection on any failed read or write like this:

defer func() {
    if err != nil { mb.close() }
}
andig commented 1 month ago

Nvm. Needs be handled on application side.