Page 1 of 1

Assertion failure causing immediate app exit in the debug mode when adding a connection

Posted: Sun Feb 26 2023 1:19 am
by yurrig
Hi there,

Thanks for the great library!

Now, the issue.

I have just got an assertion failure in the QToolBar constructor that prevents my app to start in the debug mode. A closer look shows that it is caused by broken mutex in a libguarded::SharedList<ConnectStruct>::write_handle instance in QObject::connect(). This happens when the senderListHandle is passed by value to sender.addConnection in cs_signal.h line 332, and then unlock() call when destructing the copy corrupts the mutex in the original write_handle.

I fixed the issue locally by passing the write_handle to sender.addConnection() by reference. However, the problem with copying of write_handle objects looks more general. Here is a little repro example:

Code: Select all

      libguarded::SharedList<ConnectStruct> connectList;
      {
         auto senderListHandle = connectList.lock_write();
         *senderListHandle; // access the handle - important!
         {
            auto senderListHandle2 = senderListHandle; // make a local copy that is immediately destructed
         }
      } // <-- assertion failure in the senderListHandle destructor, as both senderListHandle and senderListHandle2 share the same mutex instance
Would it make sense to make the class movable-only? Or maybe use a reference counting to make sure the unlock happens only when the last copy of a write_handle object is destroyed?

Best Regards,
Yuri

Re: Assertion failure causing immediate app exit in the debug mode when adding a connection

Posted: Fri May 19 2023 5:59 pm
by ansel
We are happy to hear you are finding CopperSpice of value.

A similar issue was reported and we were able to merge your information with the other details to solve the problem. The solution required changes in CsLibGuarded, CsSignal, and CopperSpice.

If you would like to test these changes, build CopperSpice from the following commit. You can also wait for CS 1.8.2 which will be released the end of May.

https://github.com/copperspice/copperspice/commit/ca5a8238ba93a064f0665ff0ea313170f624c863