Bug in JUCE's InterprocessConnection -> connectToPipe always returns TRUE!


Hi everyone, Hi Jules,


I found a bug in the InterprocessConnection class : when I try to connect to a pipe that was not created by another process, InterprocessConnection::connectToPipe returns TRUE.


I looked at the source code. Here are the functions called :

bool InterprocessConnection::connectToPipe (const String& pipeName, const int timeoutMs)
    ScopedPointer<NamedPipe> newPipe (new NamedPipe());
    if (newPipe->openExisting (pipeName))                                    // ==> openExisting will ALWAYS return TRUE (see below)
        const ScopedLock sl (pipeAndSocketLock);
        pipeReceiveMessageTimeout = timeoutMs;
        initialiseWithPipe (newPipe.release());
        return true;                                                                            // ==> the function will always return TRUE
    return false;

bool NamedPipe::openExisting (const String& pipeName)
    ScopedWriteLock sl (lock);
    currentPipeName = pipeName;
    return openInternal (pipeName, false);           // ==> openInternal, with false as second arg, will ALWAYS return TRUE (see below)

bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)    // ==> createPipe is FALSE
    pimpl = new Pimpl (pipeName, createPipe);
    if (createPipe && pimpl->pipeH == INVALID_HANDLE_VALUE)                          // ==> first condition is FALSE, never enter the IF bloc...
        pimpl = nullptr;
        return false;
    return true;                                                                                                          // ==> ALWAYS return TRUE when createPipe is FALSE


I'd really like to rely on InterprocessConnection::connectToPipe's return value to handle connection errors.


Thanks in advance !





I think that's correct.. IIRC if you try to open a pipe that doesn't yet exist, it'll say it succeeded, and will retry later when you write to it. (?)


OK, I understand.

In this case I will ping the connection to check if it has been created.

Thanks !


Just stumbled across this too, I find this a bit strange. What’s the point of the bool return value if it always return true?


Also, isConnected() (boiling down to calling isOpen() for the underlying NamedPipe) returns true as well after connectToPipe has been called with a non-existing pipe.