Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit153f400

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 provesto be necessary --- hopefully it won't.
1 parentd946b20 commit153f400

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/2203: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-
#ifndefSOMAXCONN
84-
#defineSOMAXCONN 5/* from Linux listen(2) man page */
85-
#endif
86-
87-
8883
staticvoidpq_close(void);
8984

9085

@@ -185,6 +180,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
185180
SockAddrsaddr;
186181
intfd,
187182
err;
183+
intmaxconn;
188184
size_tlen=0;
189185
intone=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+
returnSTATUS_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/1122:12:48 momjian Exp $
11+
* $Id: config.h.in,v 1.167 2001/07/1119:03:07 tgl Exp $
1212
*/
1313

1414
#ifndefCONFIG_H
@@ -232,6 +232,16 @@
232232
*/
233233
#defineDEFAULT_MAX_EXPR_DEPTH10000
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+
#definePG_SOMAXCONN10000
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)

[8]ページ先頭

©2009-2025 Movatter.jp