]> granicus.if.org Git - libevent/commit
windows socketpair tmpfile: use random prefix
authorPierce Lopez <pierce.lopez@gmail.com>
Sun, 26 Jul 2020 01:17:21 +0000 (21:17 -0400)
committerPierce Lopez <pierce.lopez@gmail.com>
Sun, 26 Jul 2020 22:01:35 +0000 (18:01 -0400)
commit65199178c6ee124a695a14983879921cb073c2df
treec029f3e89e1cbf2f4d077b9d6ed555e75421c230
parent85c6759926b02094920f598d050aa72eb8dc2369
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.
evutil.c