I have a class Foo that inherits from InterprocessConnection. My Foo::connectionLost has “error recovery” code that is intended to try to re-establish the connection. As instructed by the documentation, I call disconnect in my ~Foo destructor, but I take care to turn off the notification because when destroying Foo I am intentionally disconnecting and my application is “done”. I don’t want the error recovery to kick in and try to re-establish the connection. So I have
disconnect(1000, InterprocessConnection::Notify::no);
…in ~Foo().
The problem is this code in InterprocessConnection::runThread()
auto ready = socket->waitUntilReady (true, 100);
if (ready < 0)
{
deletePipeAndSocket();
connectionLostInt();
break;
}
When the InterprocessConnection is destroyed, ready the socket returns a negative value and connectionLostInt() gets called. That unconditionally calls connectionLost and now my error recovery tries to execute to re-establish the connection while the object is being deleted and chaos ensues.
It seems like connection recovery code might be common in connectionLost and so possibly this is a common use case that needs to be addressed?