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

libplctag never stops after disconnect / reconnect (AB CLX) #450

Open
joed74 opened this issue Mar 13, 2024 · 2 comments
Open

libplctag never stops after disconnect / reconnect (AB CLX) #450

joed74 opened this issue Mar 13, 2024 · 2 comments

Comments

@joed74
Copy link

joed74 commented Mar 13, 2024

If i interrupt my connection to the plc (disconnect / reconnect) libplctag never returns from plc_tag_shutdown

Attached two logs, first without interruption, second with interruption:

plc_tag_shutdown when connection was not interrupted:

2024-03-13 16:07:14.3883  INFO 1 plctag.plc_tag_shutdown:1095 thread(2) tag(0) Starting. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.plc_tag_shutdown:1101 thread(2) tag(0) Closing all tags. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.plc_tag_shutdown:1133 thread(2) tag(0) All tags closed. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.plc_tag_shutdown:1135 thread(2) tag(0) Cleaning up library resources. 
2024-03-13 16:07:14.3883  INFO 1 plctag.ab_teardown:142 thread(2) tag(0) Releasing global AB protocol resources. 
2024-03-13 16:07:14.3883  INFO 1 plctag.ab_teardown:153 thread(2) tag(0) IO thread already stopped. 
2024-03-13 16:07:14.3883  INFO 1 plctag.ab_teardown:156 thread(2) tag(0) Freeing session information. 
2024-03-13 16:07:14.3883  INFO 1 plctag.session_teardown:142 thread(2) tag(0) Starting. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.session_teardown:145 thread(2) tag(0) Waiting for sessions to terminate. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.session_teardown:162 thread(2) tag(0) Sessions all terminated. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.session_teardown:169 thread(2) tag(0) Destroying session mutex. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mutex_destroy:841 thread(2) tag(0) destroying mutex 6339D904 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mutex_destroy:854 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883  INFO 1 plctag.session_teardown:176 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883  INFO 1 plctag.ab_teardown:162 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883  INFO 1 plctag.mb_teardown:2427 thread(2) tag(0) Starting. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mb_teardown:2432 thread(2) tag(0) Waiting for all Modbus PLCs to terminate. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mb_teardown:2448 thread(2) tag(0) All Modbus PLCs terminated. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mb_teardown:2452 thread(2) tag(0) Destroying Modbus mutex. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mutex_destroy:841 thread(2) tag(0) destroying mutex 6339D910 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mutex_destroy:854 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mb_teardown:2456 thread(2) tag(0) Modbus mutex destroyed. 
2024-03-13 16:07:14.3883  INFO 1 plctag.mb_teardown:2458 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883  INFO 1 plctag.lib_teardown:176 thread(2) tag(0) Tearing down library. 
2024-03-13 16:07:14.3883  INFO 1 plctag.lib_teardown:181 thread(2) tag(0) Signaling tag tickler condition var. 
2024-03-13 16:07:14.3883  INFO 1 plctag.lib_teardown:186 thread(2) tag(0) Tearing down tag tickler thread. 
2024-03-13 16:07:14.3883  INFO 15 plctag.tag_tickler_func:646 thread(1) tag(0) Terminating. 
2024-03-13 16:07:14.3883  INFO 1 plctag.lib_teardown:193 thread(2) tag(0) Tearing down tag tickler condition var. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.cond_destroy:1242 thread(2) tag(0) Starting. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.cond_destroy:1253 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883  INFO 1 plctag.lib_teardown:199 thread(2) tag(0) Tearing down tag lookup mutex. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mutex_destroy:841 thread(2) tag(0) destroying mutex 6339D8DC 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mutex_destroy:854 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883  INFO 1 plctag.lib_teardown:205 thread(2) tag(0) Destroying tag hashtable. 
2024-03-13 16:07:14.3883  INFO 1 plctag.hashtable_destroy:260 thread(2) tag(0) Starting 
2024-03-13 16:07:14.3883  INFO 1 plctag.hashtable_destroy:272 thread(2) tag(0) Done 
2024-03-13 16:07:14.3883  INFO 1 plctag.lib_teardown:212 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mutex_destroy:841 thread(2) tag(0) destroying mutex 6339D8D0 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.mutex_destroy:854 thread(2) tag(0) Done. 
2024-03-13 16:07:14.3883 DEBUG 1 plctag.plc_tag_unregister_logger:1368 thread(2) tag(0) Starting 

plc_tag_shutdown when connection was interrupted / disconnected and reconnected:

Now there is a thread(3) ...

2024-03-13 15:57:13.5088  INFO 1 plctag.plc_tag_shutdown:1095 thread(2) tag(0) Starting. 
2024-03-13 15:57:13.5088 DEBUG 1 plctag.plc_tag_shutdown:1101 thread(2) tag(0) Closing all tags. 
2024-03-13 15:57:13.5088 DEBUG 1 plctag.plc_tag_shutdown:1133 thread(2) tag(0) All tags closed. 
2024-03-13 15:57:13.5088 DEBUG 1 plctag.plc_tag_shutdown:1135 thread(2) tag(0) Cleaning up library resources. 
2024-03-13 15:57:13.5088  INFO 1 plctag.ab_teardown:142 thread(2) tag(0) Releasing global AB protocol resources. 
2024-03-13 15:57:13.5088  INFO 1 plctag.ab_teardown:153 thread(2) tag(0) IO thread already stopped. 
2024-03-13 15:57:13.5088  INFO 1 plctag.ab_teardown:156 thread(2) tag(0) Freeing session information. 
2024-03-13 15:57:13.5088  INFO 1 plctag.session_teardown:142 thread(2) tag(0) Starting. 
2024-03-13 15:57:13.5088 DEBUG 1 plctag.session_teardown:145 thread(2) tag(0) Waiting for sessions to terminate. 
2024-03-13 15:57:13.5928 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:13.6106 DEBUG 15 plctag.tag_tickler_func:636 thread(1) tag(0) Tag tickler thread timed out waiting for something to do. 
2024-03-13 15:57:13.6106  INFO 15 plctag.tag_tickler_func:646 thread(1) tag(0) Terminating. 
2024-03-13 15:57:13.6929 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:13.7934 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:13.8939 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:13.9945 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.0953 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.1957 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.2961 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.3961 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.4965 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.5971 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.6972 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.7983 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.8984 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:14.9995 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.0996 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.2000 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.3013 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.4014 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.5023 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.6023 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.7031 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.8039 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:15.9048 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.0054 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.1058 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.2064 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.3072 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.4074 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.5075 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.6076 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.7077 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.8080 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:16.9089 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:17.0098 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:17.1100 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:17.2103 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:17.3106 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:17.4107 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:17.5116 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.session_handler:1162 thread(3) tag(0) in SESSION_IDLE state. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.session_handler:1185 thread(3) tag(0) Disconnecting due to inactivity. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.session_handler:1209 thread(3) tag(0) in SESSION_DISCONNECT state. 
2024-03-13 15:57:17.6117  INFO 17 plctag.perform_forward_close:2037 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_forward_close_req:2402 thread(3) tag(0) Starting 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.send_forward_close_req:2414 thread(3) tag(0) Forward Close connection path: 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.send_forward_close_req:2415 thread(3) tag(0) 00000 01 00 20 02 24 01 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_eip_request:1870 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_eip_request:1883 thread(3) tag(0) Sending packet of size 64 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_eip_request:1884 thread(3) tag(0) 00000 6f 00 28 00 af f9 01 40 00 00 00 00 35 4e 00 00 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_eip_request:1884 thread(3) tag(0) 00016 00 00 00 00 00 00 00 00 00 00 00 00 01 00 02 00 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_eip_request:1884 thread(3) tag(0) 00032 00 00 00 00 b2 00 18 00 4e 02 20 06 24 01 0a 05 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_eip_request:1884 thread(3) tag(0) 00048 22 12 3d f3 45 43 50 21 03 00 01 00 20 02 24 01 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.socket_write:1945 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.socket_write:2072 thread(3) tag(0) Done: result = 64. 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_eip_request:1926 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117  INFO 17 plctag.send_forward_close_req:2454 thread(3) tag(0) Done 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_forward_close_resp:2465 thread(3) tag(0) Starting 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_eip_response:1946 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.socket_read:1807 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.socket_read:1836 thread(3) tag(0) Immediate read attempt did not succeed, now wait for select(). 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.socket_read:1864 thread(3) tag(0) Socket can read data. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.socket_read:1934 thread(3) tag(0) Done: result = 24. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.socket_read:1807 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.socket_read:1934 thread(3) tag(0) Done: result = 30. 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_eip_response:2017 thread(3) tag(0) request received all needed data (54 bytes of 54). 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_eip_response:2019 thread(3) tag(0) 00000 6f 00 1e 00 af f9 01 40 00 00 00 00 35 4e 00 00 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_eip_response:2019 thread(3) tag(0) 00016 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_eip_response:2019 thread(3) tag(0) 00032 00 00 00 00 b2 00 0e 00 ce 00 00 00 22 12 3d f3 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_eip_response:2019 thread(3) tag(0) 00048 45 43 50 21 00 00 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_eip_response:2026 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_forward_close_resp:2494 thread(3) tag(0) Connection close succeeded. 
2024-03-13 15:57:17.6117  INFO 17 plctag.recv_forward_close_resp:2499 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117  INFO 17 plctag.perform_forward_close:2053 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.session_handler:1220 thread(3) tag(0) in SESSION_UNREGISTER state. 
2024-03-13 15:57:17.6117  INFO 17 plctag.session_unregister:777 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117  INFO 17 plctag.session_unregister:781 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.session_handler:1231 thread(3) tag(0) in SESSION_CLOSE_SOCKET state. 
2024-03-13 15:57:17.6117  INFO 17 plctag.session_close_socket:790 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117  INFO 17 plctag.socket_close:2083 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117  INFO 17 plctag.socket_close:2119 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117  INFO 17 plctag.socket_destroy:2128 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117  INFO 17 plctag.socket_close:2083 thread(3) tag(0) Starting. 
2024-03-13 15:57:17.6117  INFO 17 plctag.socket_close:2119 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117  INFO 17 plctag.socket_destroy:2145 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117  INFO 17 plctag.session_close_socket:798 thread(3) tag(0) Done. 
2024-03-13 15:57:17.6117 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:17.7140 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:17.8143 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:17.9152 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.0156 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.1157 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.2169 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.3172 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.4180 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.5182 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.6191 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.7194 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.8205 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:18.9210 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.0214 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.1220 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.2240 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.3247 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.4251 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.5257 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.6261 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.7264 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.8270 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:19.9275 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.0283 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.1284 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.2304 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.3308 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.4309 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.5312 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.6324 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.7328 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.8333 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:20.9339 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.0347 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.1355 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.2356 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.3358 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.4360 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.5368 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.6375 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.7378 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.8388 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:21.9396 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.0413 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.1422 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.2430 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.3435 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.4443 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.5447 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.6456 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.7459 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.8463 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:22.9467 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.0472 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.1476 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.2479 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.3486 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.4495 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.5503 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.6512 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.7518 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.8525 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:23.9526 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.0530 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.1533 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.2536 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.3539 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.4543 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.5552 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.6556 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.7560 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.8568 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:24.9574 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
2024-03-13 15:57:25.0588 DEBUG 17 plctag.session_handler:1270 thread(3) tag(0) in SESSION_WAIT_RECONNECT state. 
@kyle-github
Copy link
Member

Interesting. Thanks for the report. The third thread appears to be the thread for the PLC connection. It should have been set to terminate, but it looks like the timing/coordination is not working right. This might take me some time to debug. I am going to mark this as a bug for now. Thanks again!

@joed74
Copy link
Author

joed74 commented Mar 20, 2024

diff --git a/session.c b/session.c
index 3c36271..60dc163 100644
--- a/session.c
+++ b/session.c
@@ -71,7 +71,7 @@
 #define SOCKET_WAIT_TIMEOUT_MS (20)
 #define SESSION_IDLE_WAIT_TIME (100)
 
-
+volatile int ab_session_terminating = 0;
 
 static ab_session_p session_create_unsafe(const char *host, const char *path, plc_type_t plc_type, int *use_connected_msg, int connection_group_id);
 static int session_init(ab_session_p session);
@@ -141,6 +141,8 @@ void session_teardown()
 {
     pdebug(DEBUG_INFO, "Starting.");
 
+    ab_session_terminating = 1;
+
     if(sessions && session_mutex) {
         pdebug(DEBUG_DETAIL, "Waiting for sessions to terminate.");
 
@@ -173,6 +175,8 @@ void session_teardown()
         session_mutex = NULL;
     }
 
+    ab_session_terminating = 0;
+
     pdebug(DEBUG_INFO, "Done.");
 }
 
@@ -1031,7 +1035,7 @@ THREAD_FUNC(session_handler)
 
     pdebug(DEBUG_INFO, "Starting thread for session %p", session);
 
-    while(!session->terminating) {
+    while(!session->terminating && !ab_session_terminating) {
         /* how long should we wait if nothing wakes us? */
         wait_until_time = time_ms() + SESSION_IDLE_WAIT_TIME;
 
@@ -1321,6 +1325,9 @@ THREAD_FUNC(session_handler)
         purge_aborted_requests_unsafe(session);
     }
 
+    if (ab_session_terminating)
+        session_destroy(session);
+
     THREAD_RETURN(0);
 }
 

session.patch

I just added an ab_session_terminating flag which will be set in session_teardown and ends all remaining THREAD_FUNCs with additionally destroying the session. Now plctag_shutdown never hangs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@kyle-github @joed74 and others