-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closing handlers and TCP connection state #48
Comments
Did you test this in an extra debug/test program or can independent/higher-level program logic cause this? I wonder because the exposed close and internal closeIdle method of tcpTransport call the same internal close to terminate the TCP connection.
|
I'm confident in my testing. |
Not sure if i understood your control flow correctly. Does it look like this?func newModbusClient() modbus.Client {
h := modbus.NewTCPClientHandler("127.0.0.1:502")
if err := h.Connect(); err != nil {
panic(err)
}
defer h.Close()
return modbus.NewClient(h)
}
func main() {
c := newModbusClient()
if _, err := c.WriteSingleRegister(0xFF, 0xFF); err != nil {
panic(err)
}
} would be good if you could share some code and logs if available. |
Is this still a thing @StevenResiot?
My guess is that your |
@StevenResiot a minimal reproducing example code would indeed be very useful here, without this I don't know how to proceed here |
Whenever I close a handler, any open TCP connection underneath stays open (and times out after idling - default 60seconds).
As my program dynamically opens connections to different slave servers, and as a customer is running a Modbus server that only allows one connection per IP(ugh, I know), I find myself stuck in having a single connection that customers do not always have a reference to. Additionally, I have customers wanting to access the server with different timeout settings so I'm kind of stuck as connection settings cannot really be changed after a connection is open.
Long story short: I need to open connections, do my thing, and disconnect right away. The only way I found so far is to set an IdleTimeout of a few milliseconds, but this is far from optimal.
How do I close an open TCP connection? Closing the handler doesn't close its open connections, and there's no Close method for the Client object.
Cheers
The text was updated successfully, but these errors were encountered: