InterprocessConnection re-usable?


#1

Is InterprocessConnection designed to be re-usable at the client end, or should we delete it after each use?

While reconnecting after a disconnect works most of the time, there are instances where it does not seem to work (at the client end, socket connections) and even happens to crash the process. The server end always reconnects fine. I do have a difficult time reproducing and debugging this, hence my question.


#2

I'd suggest deleting it.. It's always cleaner to do that, and the overhead is negligible.


#3

Thanks!

Just did a test and hope it will eliminate the occasional crashes.


#4

There's a related issue, which needs a fix:

In InterprocessConnection::connectToSocket(...), clients get notified that the connection was made with connectionMadeInt() ... connectionMade(), etc, while isConnected() still returns false! This is because isConnected() also checks if the thread is running, which is not the case at that point. Instead of

if (socket->connect (hostName, portNumber, timeOutMillisecs))
{
    connectionMadeInt();
    thread->startThread();
    return true;
}

the sequence should be changed to

if (socket->connect (hostName, portNumber, timeOutMillisecs))
{
     thread->startThread();
     connectionMadeInt();
     return true;
}

which ensures that isConnected() returns true for everyone listening to the connectionMade() callback.

I stumbled across this wondering why the connection was not connected after it was just made ;-)


#5

Ahhh, there's also a race condition: The thread takes some time to come up, which happens to race against the execution of connectionMade().

Actually connectionMade() should not be sent before the connection is ready to use. Unless I'm missing the intention behind this.

At least I'm beginning to realize now what had my apps behaving unpredictable at times ;-)