Giter Club home page Giter Club logo

Comments (3)

kyle-github avatar kyle-github commented on July 22, 2024

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!

from libplctag.

joed74 avatar joed74 commented on July 22, 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...

from libplctag.

kyle-github avatar kyle-github commented on July 22, 2024

I am just getting back to you, sorry for the delay!

I am not sure why adding an additional flag would make this work. The existing session->terminating flag should be sufficient.

I have not been able to reproduce this. Are the steps here:

  1. let libplctag connect to a PLC.
  2. interrupt the connection (by turning off the PLC? by pulling the Ethernet cable?)
  3. terminate the session by closing the last tag.

Is that correct?

from libplctag.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.