Beckhoff / ADS

Beckhoff protocol to communicate with TwinCAT devices.
MIT License
491 stars 193 forks source link

Unreachable PLC Blocks All Other Operations During Timeout Period #208

Closed ashmookler1 closed 10 months ago

ashmookler1 commented 11 months ago

Hello,

We are using this library from a multithreaded application that connects to multiple PLCs. Whenever a PLC becomes unreachable, the library blocks all activity on all other PLCs during the 3 connection attempt timeout period. For example:

If our program is connected to 10 PLCs (A though J), and the connection timeout is set to 3 seconds, and PLC A goes offline, the next time the program attempts to connect to PLC A or run an operation on it, the library will block all other operations for PLCs B through J for 9 seconds.

This has the effect that an unresponsive PLC causes all other PLCs on the system to stop collecting data and any other operation for the entirety of the timeout window.

I looked at the code, and I think this is happening because the AmsRouter uses lock_guard with a shared mutex, and the lock remains engaged during the entire attempt to communicate with the PLC, leading to the blocking of all other operations for the entire timeout period.

Is this intended behavior? Is there a workaround for it, such as a way to check if communication is available with the PLC in a non-blocking way before attempting a connection or operation to prevent the timeout from happening in the first place?

As it is, this significantly degrades data quality because any time a PLC becomes unreachable all data collection is stopped for a long time for all connected PLCs.

Thank you!

Abe

pbruenn commented 11 months ago

@ashmookler1 Sorry I was on vacation but @nicolatimeus did a fix, which I prepared for merge here https://github.com/Beckhoff/ADS/commit/5dbbfade98d4b8e93b623d8519d0e7c931a6c4d2. Are you able to confirm that your problem is fixed with that patch?

ashmookler1 commented 10 months ago

I am working on this issue with @nicolatimeus, if he's satisfied with the resolution, I am too and this can be closed.