Skip to content

Commit

Permalink
Instead of believing SOMAXCONN from the system header files (which is
Browse files Browse the repository at this point in the history
a lie on many Unixen), invoke listen() with MIN(MaxBackends*2, 10000).
The clamp value 10000 is configurable in config.h.in, if that proves
to be necessary --- hopefully it won't.
  • Loading branch information
tglsfdc committed Jul 11, 2001
1 parent d946b20 commit 153f400
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
28 changes: 21 additions & 7 deletions src/backend/libpq/pqcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pqcomm.c,v 1.117 2001/03/22 03:59:30 momjian Exp $
* $Id: pqcomm.c,v 1.118 2001/07/11 19:03:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Expand Down Expand Up @@ -80,11 +80,6 @@
#include "miscadmin.h"


#ifndef SOMAXCONN
#define SOMAXCONN 5 /* from Linux listen(2) man page */
#endif


static void pq_close(void);


Expand Down Expand Up @@ -185,6 +180,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
SockAddr saddr;
int fd,
err;
int maxconn;
size_t len = 0;
int one = 1;

Expand Down Expand Up @@ -350,7 +346,25 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
}
#endif /* HAVE_UNIX_SOCKETS */

listen(fd, SOMAXCONN);
/*
* Select appropriate accept-queue length limit. PG_SOMAXCONN is
* only intended to provide a clamp on the request on platforms where
* an overly large request provokes a kernel error (are there any?).
*/
maxconn = MaxBackends * 2;
if (maxconn > PG_SOMAXCONN)
maxconn = PG_SOMAXCONN;

err = listen(fd, maxconn);
if (err < 0)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"FATAL: StreamServerPort: listen() failed: %s\n",
strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
return STATUS_ERROR;
}

*fdP = fd;

Expand Down
12 changes: 11 additions & 1 deletion src/include/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* or in config.h afterwards. Of course, if you edit config.h, then your
* changes will be overwritten the next time you run configure.
*
* $Id: config.h.in,v 1.166 2001/06/11 22:12:48 momjian Exp $
* $Id: config.h.in,v 1.167 2001/07/11 19:03:07 tgl Exp $
*/

#ifndef CONFIG_H
Expand Down Expand Up @@ -232,6 +232,16 @@
*/
#define DEFAULT_MAX_EXPR_DEPTH 10000

/*
* PG_SOMAXCONN: maximum accept-queue length limit passed to listen(2).
* You'd think we should use SOMAXCONN from <sys/socket.h>, but on many
* systems that symbol is much smaller than the kernel's actual limit.
* In any case, this symbol need be twiddled only if you have a kernel
* that refuses large limit values, rather than silently reducing the
* value to what it can handle (which is what most if not all Unixen do).
*/
#define PG_SOMAXCONN 10000

/*
* You can try changing this if you have a machine with bytes of another
* size, but no guarantee...
Expand Down

0 comments on commit 153f400

Please sign in to comment.