summaryrefslogtreecommitdiff
path: root/src/backend/libpq/pqcomm.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-02-08 15:52:40 -0500
committerRobert Haas <rhaas@postgresql.org>2022-02-08 15:53:19 -0500
commitaa64f23b02924724eafbd9eadbf26d85df30a12b (patch)
tree54f72bfd7e36c2e879dc87149eb94db220d1cae3 /src/backend/libpq/pqcomm.c
parent2da896182ce11240774af6c4d769777f90a09536 (diff)
downloadpostgresql-aa64f23b02924724eafbd9eadbf26d85df30a12b.tar.gz
Remove MaxBackends variable in favor of GetMaxBackends() function.
Previously, it was really easy to write code that accessed MaxBackends before we'd actually initialized it, especially when coding up an extension. To make this less error-prune, introduce a new function GetMaxBackends() which should be used to obtain the correct value. This will ERROR if called too early. Demote the global variable to a file-level static, so that nobody can peak at it directly. Nathan Bossart. Idea by Andres Freund. Review by Greg Sabino Mullane, by Michael Paquier (who had doubts about the approach), and by me. Discussion: http://postgr.es/m/20210802224204.bckcikl45uezv5e4@alap3.anarazel.de
Diffstat (limited to 'src/backend/libpq/pqcomm.c')
-rw-r--r--src/backend/libpq/pqcomm.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index f05723dc92..22eb04948e 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -349,6 +349,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
struct addrinfo hint;
int listen_index = 0;
int added = 0;
+ int max_backends = GetMaxBackends();
#ifdef HAVE_UNIX_SOCKETS
char unixSocketPath[MAXPGPATH];
@@ -571,7 +572,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
* 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;
+ maxconn = max_backends * 2;
if (maxconn > PG_SOMAXCONN)
maxconn = PG_SOMAXCONN;