Skip to content

Commit 0e92f98

Browse files
committed
On win32, don't use SO_REUSEADDR for TCP sockets.
Per failure on buildfarm member baiji and subsequent discussion.
1 parent 9539e64 commit 0e92f98

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/backend/libpq/pqcomm.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
33-
* $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.191 2007/03/03 19:32:54 neilc Exp $
33+
* $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.192 2007/06/04 11:59:20 mha Exp $
3434
*
3535
*-------------------------------------------------------------------------
3636
*/
@@ -337,6 +337,16 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
337337
continue;
338338
}
339339

340+
#ifndef WIN32
341+
/*
342+
* Without the SO_REUSEADDR flag, a new postmaster can't be started right away after
343+
* a stop or crash, giving "address already in use" error on TCP ports.
344+
*
345+
* On win32, however, this behavior only happens if the SO_EXLUSIVEADDRUSE is set.
346+
* With SO_REUSEADDR, win32 allows multiple servers to listen on the same address,
347+
* resulting in unpredictable behavior. With no flags at all, win32 behaves as
348+
* Unix with SO_REUSEADDR.
349+
*/
340350
if (!IS_AF_UNIX(addr->ai_family))
341351
{
342352
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
@@ -349,6 +359,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
349359
continue;
350360
}
351361
}
362+
#endif
352363

353364
#ifdef IPV6_V6ONLY
354365
if (addr->ai_family == AF_INET6)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy