From: Marko Kreen Date: Mon, 18 Mar 2013 16:01:52 +0000 (+0200) Subject: win32: Don't set SO_REUSEADDR on listen socket. X-Git-Tag: pgbouncer_1_6_rc1~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45857fabab6d9b7230a4d01ad9d7068cf4dce30e;p=pgbouncer win32: Don't set SO_REUSEADDR on listen socket. According to Postgres src/backend/libpq/pqcomm.c: /* * Without the SO_REUSEADDR flag, a new postmaster can't be started * right away after a stop or crash, giving "address already in use" * error on TCP ports. * * On win32, however, this behavior only happens if the * SO_EXLUSIVEADDRUSE is set. With SO_REUSEADDR, win32 allows multiple * servers to listen on the same address, resulting in unpredictable * behavior. With no flags at all, win32 behaves as Unix with * SO_REUSEADDR. */ --- diff --git a/src/pooler.c b/src/pooler.c index 16cef9c..b5848b7 100644 --- a/src/pooler.c +++ b/src/pooler.c @@ -97,6 +97,8 @@ static bool add_listen(int af, const struct sockaddr *sa, int salen) if (sock < 0) goto failed; + /* SO_REUSEADDR behaviour it default in WIN32. */ +#ifndef WIN32 /* relaxed binding */ if (af != AF_UNIX) { val = 1; @@ -105,6 +107,7 @@ static bool add_listen(int af, const struct sockaddr *sa, int salen) if (res < 0) goto failed; } +#endif #ifdef IPV6_V6ONLY /* avoid ipv6 socket's attempt to takeover ipv4 port */