Hi,
I stumbled across an error in the linux implementation. I couldn't give you exact steps to reproduce since our setup is a bit complex and it costs too much time to simplify it.
In short: I start a async read operation from the "main thread" using the callback for notification. In this callback I start the next operation. The objects are correctly locked with mutexes etc.
I'm using std::shared_ptr (and weak_ptr) to manage the lifetime of the objects. With this it could happen that the mainthread is releasing my management objects while a operation response is processed. So the management objects are getting freed in the callback-thread. Since this leads to errors (freeing the object which contains the thread who is executing the callback), I use some kind of garbage collector to free the objects in the main thread.
So after the response callback is processed, I call "disconnect" in the thread and put the S7Wrapper object into the GC list.
Sometimes when the GC wants to delete the S7Wrapper object (some seconds after "disconnect") I get a "SIG ABORT" with: FATAL: exception not rethrown
This is reproducable in our application within 2minutes (where I free/recreate the objects every 30 seconds for stress testing)
After googling a bit and searching in the Snap7 sources I suppose that the following is happen:
TSnap7Client::~TSnap7Client()
...
TSnap7Client::CloseThread()
...
[1] if (FThread->WaitFor(Timeout)!=WAIT_OBJECT_0)
FThread->Kill();
...
....
I think [1] is timing out (don't know why - I'm currently not able to debug Snap7) and thus the thread should be killed.
Herbey the thread should be canceled which is done via exceptions in lib-pthread.
This leads me to the actual problem:
snap_thread.cpp, line 46 - 51:
try { Thread->Execute(); } catch (...) { };
The catch block is catching ALL exceptions but the pthread-exceptions needs to be reraised in order to work correctly!
Source of information: http://udrepper.livejournal.com/tag/linux%20nptl%20c++%20cancellation%20exceptions
After inserting:
} catch (abi::_ _forced_unwind&) {
throw;
before the catch(...) block, my test application is running without problems (several hours).
Would you like to add this fix to the snap_threads.cpp? (I ifdefed it with POSIX and OS_OSX)
Hi, I also found this bug and the same solution. I attached a patch that implements the fix.
See also: https://github.com/gijzelaerr/python-snap7/issues/26
Last edit: Pelle van der Heide 2017-03-01