diff --git a/fishd.cpp b/fishd.cpp index e5edc3da5..edb79c22f 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -529,6 +529,14 @@ static bool acquire_socket_lock(const std::string &sock_name, std::string *out_l */ static int get_socket(void) { + // Cygwin has random problems involving sockets. When using Cygwin, + // allow 20 attempts at making socket correctly. +#ifdef __CYGWIN__ + int attempts = 0; +repeat: + attempts += 1; +#endif + int s, len, doexit = 0; int exitcode = EXIT_FAILURE; struct sockaddr_un local; @@ -599,6 +607,10 @@ unlock: if (doexit) { + // If Cygwin, only allow normal quit when made lots of attempts. +#ifdef __CYGWIN__ + if (exitcode && attempts < 20) goto repeat; +#endif exit_without_destructors(exitcode); }