aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-02-13 19:18:54 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-02-13 19:18:54 +0000
commitcf4cc7843c17db5142a12edddb1bd17b33ea72d8 (patch)
tree20ef33b781de4f4489bb1599edaa6dfd391b17fa
parentb9c65aed82a487c51a7d3b8bdfb731141215ba5a (diff)
downloadpostgresql-cf4cc7843c17db5142a12edddb1bd17b33ea72d8.tar.gz
postgresql-cf4cc7843c17db5142a12edddb1bd17b33ea72d8.zip
Improve postmaster's behavior if an accept() call fails. Because the server
socket is still read-ready, the code was a tight loop, wasting lots of CPU. We can't do anything to clear the failure, other than wait, but we should give other processes more chance to finish and release FDs; so insert a small sleep. Also, avoid bogus "close(-1)" in this case. Per report from Jim Nasby.
-rw-r--r--src/backend/libpq/pqcomm.c12
-rw-r--r--src/backend/postmaster/postmaster.c5
2 files changed, 13 insertions, 4 deletions
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 4af67963035..a8f40249c9d 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -30,7 +30,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.189 2007/01/05 22:19:29 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.190 2007/02/13 19:18:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -528,7 +528,7 @@ Setup_AF_UNIX(void)
/*
* StreamConnection -- create a new connection with client using
- * server port.
+ * server port. Set port->sock to the FD of the new connection.
*
* ASSUME: that this doesn't need to be non-blocking because
* the Postmaster uses select() to tell when the server master
@@ -548,6 +548,14 @@ StreamConnection(int server_fd, Port *port)
ereport(LOG,
(errcode_for_socket_access(),
errmsg("could not accept new connection: %m")));
+ /*
+ * If accept() fails then postmaster.c will still see the server
+ * socket as read-ready, and will immediately try again. To avoid
+ * uselessly sucking lots of CPU, delay a bit before trying again.
+ * (The most likely reason for failure is being out of kernel file
+ * table slots; we can do little except hope some will get freed up.)
+ */
+ pg_usleep(100000L); /* wait 0.1 sec */
return STATUS_ERROR;
}
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 2c54ad7010e..d0fe8451987 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.520 2007/02/11 11:59:25 mha Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.521 2007/02/13 19:18:54 tgl Exp $
*
* NOTES
*
@@ -1710,7 +1710,8 @@ ConnCreate(int serverFd)
if (StreamConnection(serverFd, port) != STATUS_OK)
{
- StreamClose(port->sock);
+ if (port->sock >= 0)
+ StreamClose(port->sock);
ConnFree(port);
port = NULL;
}