Skip to content

Commit 153f400

Browse files
committed
Instead of believing SOMAXCONN from the system header files (which is
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.
1 parent d946b20 commit 153f400

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/backend/libpq/pqcomm.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
3030
* Portions Copyright (c) 1994, Regents of the University of California
3131
*
32-
* $Id: pqcomm.c,v 1.117 2001/03/22 03:59:30 momjian Exp $
32+
* $Id: pqcomm.c,v 1.118 2001/07/11 19:03:07 tgl Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -80,11 +80,6 @@
8080
#include "miscadmin.h"
8181

8282

83-
#ifndef SOMAXCONN
84-
#define SOMAXCONN 5 /* from Linux listen(2) man page */
85-
#endif
86-
87-
8883
static void pq_close(void);
8984

9085

@@ -185,6 +180,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
185180
SockAddr saddr;
186181
int fd,
187182
err;
183+
int maxconn;
188184
size_t len = 0;
189185
int one = 1;
190186

@@ -350,7 +346,25 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
350346
}
351347
#endif /* HAVE_UNIX_SOCKETS */
352348

353-
listen(fd, SOMAXCONN);
349+
/*
350+
* Select appropriate accept-queue length limit. PG_SOMAXCONN is
351+
* only intended to provide a clamp on the request on platforms where
352+
* an overly large request provokes a kernel error (are there any?).
353+
*/
354+
maxconn = MaxBackends * 2;
355+
if (maxconn > PG_SOMAXCONN)
356+
maxconn = PG_SOMAXCONN;
357+
358+
err = listen(fd, maxconn);
359+
if (err < 0)
360+
{
361+
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
362+
"FATAL: StreamServerPort: listen() failed: %s\n",
363+
strerror(errno));
364+
fputs(PQerrormsg, stderr);
365+
pqdebug("%s", PQerrormsg);
366+
return STATUS_ERROR;
367+
}
354368

355369
*fdP = fd;
356370

src/include/config.h.in

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* or in config.h afterwards. Of course, if you edit config.h, then your
99
* changes will be overwritten the next time you run configure.
1010
*
11-
* $Id: config.h.in,v 1.166 2001/06/11 22:12:48 momjian Exp $
11+
* $Id: config.h.in,v 1.167 2001/07/11 19:03:07 tgl Exp $
1212
*/
1313

1414
#ifndef CONFIG_H
@@ -232,6 +232,16 @@
232232
*/
233233
#define DEFAULT_MAX_EXPR_DEPTH 10000
234234

235+
/*
236+
* PG_SOMAXCONN: maximum accept-queue length limit passed to listen(2).
237+
* You'd think we should use SOMAXCONN from <sys/socket.h>, but on many
238+
* systems that symbol is much smaller than the kernel's actual limit.
239+
* In any case, this symbol need be twiddled only if you have a kernel
240+
* that refuses large limit values, rather than silently reducing the
241+
* value to what it can handle (which is what most if not all Unixen do).
242+
*/
243+
#define PG_SOMAXCONN 10000
244+
235245
/*
236246
* You can try changing this if you have a machine with bytes of another
237247
* size, but no guarantee...

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