Skip to content
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

input.modbus TCP connection handling #8225

Closed
mihailescu2m opened this issue Oct 6, 2020 · 8 comments · Fixed by #9256
Closed

input.modbus TCP connection handling #8225

mihailescu2m opened this issue Oct 6, 2020 · 8 comments · Fixed by #9256
Labels
area/modbus bug unexpected problem or unintended behavior

Comments

@mihailescu2m
Copy link

It seems that after successfully gathering data over modbus TCP, the connection is not released.
This makes the telegraf plugin have unique access to the modbus device, and other connections fail even if telegraf is not actively gathering data but it's idle waiting for the next interval.
Can this be fixed?

@mihailescu2m mihailescu2m added the bug unexpected problem or unintended behavior label Oct 6, 2020
@ssoroka
Copy link
Contributor

ssoroka commented Oct 7, 2020

definitely! which modbus plugin are you using?

@mihailescu2m
Copy link
Author

I am using the default telegraf plugin

example config:

[[inputs.modbus]]
  name = "inverter"
  slave_id = 1
  interval = "10s"
  timeout = "4s"
  controller = "tcp://inverter:1502"
  holding_registers = [
    { name = "dcPower",           byte_order = "AB",   data_type = "INT16",  scale=1.0, address = [40100]},
    ...

@ssoroka
Copy link
Contributor

ssoroka commented Dec 1, 2020

It looks like it defaults to disconnecting after a minute of no activity, which seems like a reasonable default. Are you seeing any problems with connections left open longer than that, or issues with the connections not being used?

@sjwang90
Copy link
Contributor

@mihailescu2m ping

It looks like it defaults to disconnecting after a minute of no activity, which seems like a reasonable default. Are you seeing any problems with connections left open longer than that, or issues with the connections not being used?

@mihailescu2m

@mihailescu2m
Copy link
Author

The problem is when I am trying to access the same device over modbus from another software.
So let's say every minute at :00 and :30, telegraf gathers data (~3 seconds duration), and I want another software, also every minute at :15 and :45 to access modbus (for ~3 seconds). This is impossible, since basically telegraf never releases the connection (and there can be only 1 client connection)

@rwalli
Copy link

rwalli commented Feb 25, 2021

I can confirm the bug with tcp-timeout and in my case i figured out that telegraf close the TCP-connection after the “intervall-setting”.

@srebhan
Copy link
Member

srebhan commented Mar 1, 2021

@mihailescu2m telegraf definitively does not close the connection after the query. A pull-request adding a disconnection_after_query (or some less-bulky name) taking a boolen or, even better reconnect_after_queries taking a number of queries (zero = do not disconnect) is welcome.

@srebhan
Copy link
Member

srebhan commented Jun 14, 2021

@mihailescu2m and @rwalli I implemented a disconnection setting in PR #9256. It would be nice if you can test the new setting. You can use the artifacts built by CI and add the following to your modbus-plugin config:

workarounds = {
  close_connection_after_gather = false
}

Please let me know if you find any issue. Thanks you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/modbus bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants