netconf icon indicating copy to clipboard operation
netconf copied to clipboard

Add autoconnect feature or make disconnected returned error simple

Open guo1017138 opened this issue 11 months ago • 1 comments

This is not an issue, but I suggest to enhance it for rainy day case.

Problem Description:

  1. started a netconf client normally, make sure it works.
  2. restart netconf server to simulate server restart / network issue.
  3. clients won't work again.

Workaround: I can detect it by the following code sample. But I need to detect several errors as following per my expierence(maybe not all, just what I found). If this lib can support autoconnect feature such like Rockwell AB PLC or just make returned error to be simple will be better.


func (c *Client) checkNetworkError(err error) {
	if err == nil {
		return
	}
	_, ok := err.(net.Error)
	if ok ||
		strings.Contains(err.Error(), "connection closed unexpectedly") ||
		strings.Contains(err.Error(), "EOF") ||
		strings.Contains(err.Error(), "existing message writer still open") {
		c.Logger.Error("network error, reconnecting...")
		err = c.reconnect()
		if err != nil {
			c.Logger.Errorf("reconnect failed: %v", err)
			return
		}
		c.Logger.Info("reconnect success")
	}
}

guo1017138 avatar Jan 03 '25 01:01 guo1017138

I think both are needed. I've been meaning to clean up transport errors (and fail on any error from the transport).

I have been tossing around the idea of a higher order "pool" package which would handle not only reconnects when there are failures (or lazy connect) but also be able to handle multiple requests over multiple sockets up to some set value. This would be a good use case here (with maxConnection set to 1)

nemith avatar Jan 04 '25 00:01 nemith