Closing an juce::InterprocessConnectionServer



On Linux we have a problem stopping an InterprocessConnectionServer cleanly. The problem is that it will internally create a Socket and call waitForNextConnection(), which will hang indefinitely if there is no incoming connection.

When stopping the server, it tries to unblock this call by creating a connection (juce_Socket.cpp line 380), but fails. I investigated this a bit but couln't find the problem. I know that in juce_Socket.cpp on line 176 the getsockopt() call returns ECONNREFUSED.

It worked correctly before we upgraded to JUCE 3. Any thoughts on what could be the issue?



That's odd - linux should work the same as OSX where I've tested that stuff quite heavily.

Do you have a snippet of test code that I could use to reproduce it?


There's nothing special about reproducing this issue. So probably this is system dependent:

class TestServer : public InterprocessConnectionServer
    virtual InterprocessConnection* createConnectionObject() { return nullptr; }
    TestServer s;

I did some testing and found out that it's only possible to connect to the socket using IPv4 localhost address ( and not when using the IPv6 link-local address (::1).

I ran Wireshark, and it turns out the temporary connection is going to ::1, so it fails.

A temporary fix is to replace "localhost" with "" on line 386 in juce_Socket.cpp. Making sure IPv6 works is a bit involved, as described here:



Perhaps a good fix for that line in Socket would be:

            temp.connect (IPAddress::local().toString(), portNumber, 1000);

(I guess the IPAddress class will have to be changed to deal with IPv6 eventually anyway)


I can confirm it works after updating JUCE, thanks.