plc4x icon indicating copy to clipboard operation
plc4x copied to clipboard

[Bug]: TriggeredScraperTask thread silenly completed after TimeoutException

Open geneross opened this issue 1 year ago • 3 comments

What happened?

I've faced with a situation when scheduled earlier TriggeredScraperTask has completed after getting TimeoutException in execution of PlcReadRequest. The scenario is pull data from server every 50ms for kafka connector.

https://github.com/apache/plc4x/blob/8f914109bb6047af35dc909d3851273e17277b2e/plc4j/tools/scraper/src/main/java/org/apache/plc4x/java/scraper/triggeredscraper/TriggeredScraperTask.java#L126-L135

Changing code to

                    plcReadResponse = readRequestBuilder
                        .build()
                        .execute()
                        .orTimeout(requestTimeoutMs, TimeUnit.MILLISECONDS)
                        .get();

improves the situation. Read request still complete exceptionally and LeasedPlcConnection sets invalidateConnection flag so leased connection on close return connection to the connection container with request to invalidate cached connections.

Version

v0.12.0

Programming Languages

  • [X] plc4j
  • [ ] plc4go
  • [ ] plc4c
  • [ ] plc4net

Protocols

  • [ ] AB-Ethernet
  • [ ] ADS /AMS
  • [ ] BACnet/IP
  • [ ] CANopen
  • [ ] DeltaV
  • [ ] DF1
  • [ ] EtherNet/IP
  • [ ] Firmata
  • [ ] KNXnet/IP
  • [ ] Modbus
  • [X] OPC-UA
  • [ ] S7

geneross avatar Dec 14 '23 13:12 geneross

The cause is in async getting connection. Sometime call of getConnection throws checked exception and it makes execution thread completion.

geneross avatar Jan 19 '24 16:01 geneross

Root the problem is in LeasedPlcConnection. readRequestBuilder() method returns ReadRequestRequest.Builder descendant that later uses result of connection.get() to build instance of PlcReadRequest. But at the time of call leased connection may have already returned and execution will end with NullPoinerException. This in turn cause completion of execution threads in TriggerScraperImpl and kafka source connector no longer retrieve information from server.

Proposed PR here: https://github.com/apache/plc4x/pull/1361/files

geneross avatar Jan 24 '24 10:01 geneross

As the proposed PR is merged, can this issue be closed?

chrisdutz avatar Jun 30 '24 12:06 chrisdutz