Commit 65199178c6ee124a695a14983879921cb073c2df

Pierce Lopez 2020-07-25T21:17:21

windows socketpair tmpfile: use random prefix fixes #1058 GetTempFileNameA() takes an optional prefix, and a "unique" long value which can optionally be zero, which causes it to automatically increment until a not-yet-existing filename is found. When libevent creates many AF_UNIX socketpairs on windows, it slows down dramatically, due to always using the same blank prefix, and GetTempFileNameA() needing to iterate through all the existing socketpair filenames. With a present and varying prefix, it will have much less need to iterate. It was also possible for a race with other processes also using blank-prefix tmpfile names to result in both trying to start using the same name at the same time (because libevent deletes the file and then re-creates it as a unix socket), which should now be much less likely. Unfortuantely, "much" is just a factor of 32k, because the prefix is only 3 characters, and windows filesystems are case-insensitive, so doing better would require more sophisticated windows API usage and charset trickyness.