IPC Socket timing problems?

I experience some problems under Windows (macOS is fine) when I try to open several IPC sockets from a desktop app to console helper applications started from the main app. Is it possible that it is somehow toxic to establish more than one connection at a time – currently it looks that I should wait for one connection success before starting the next one. (The problem does not exist if the connections are opened manually one after another)
I cannot find anything in the docs about it, but could this be a possible failure reason? Or should I look in different directions?

In general IPC socket on Windows is not as reliable as it’s on Mac. I had multiple problems with it and one in particular might be of help for you.

My experience on using it to open multiple sockets turned out to fall into the problem of having the mechanism to calculate the port providing duplicates.

To be clear, on Windows IPC is basically a loopback TCP socket attached to a port which is calculated with a known algorithm starting from a string (the IPCSocket.Path). This happened to me to provide often duplicate ports in case of multiple sockets opened.

Consider the Path for Windows has not to be a real path, it can safely be replaced with a random string.
I solved generating a UUID on the fly for each socket as a Path. This considerably reduced the chance of getting the same port number. For the remaining situations where a duplicate is still provided I simply let the program to try with another UUID for like 5 times. This appeared to work.

Here are some more information on how the Path is used to compute the socket port:


Thank you, Massimo! I tweaked the initialization and now open another socket only after the previous one has initialized fully. That seems to do the trick.