Skip to content

Commit dd1c781

Browse files
committed
Make get_stack_depth_rlimit() handle RLIM_INFINITY more sanely.
Rather than considering this result as meaning "unknown", report LONG_MAX. This won't change what superusers can set max_stack_depth to, but it will cause InitializeGUCOptions() to set the built-in default to 2MB not 100kB. The latter seems like a fairly unreasonable interpretation of "infinity". Per my investigation of odd buildfarm results as well as an old complaint from Heikki. Since this should persuade all the buildfarm animals to use a reasonable stack depth setting during "make check", revert previous patch that dumbed down a recursive regression test to only 5 levels.
1 parent 6736916 commit dd1c781

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/backend/tcop/postgres.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
#include "postgres.h"
2121

22+
#include <fcntl.h>
23+
#include <limits.h>
24+
#include <signal.h>
2225
#include <time.h>
2326
#include <unistd.h>
24-
#include <signal.h>
25-
#include <fcntl.h>
2627
#include <sys/socket.h>
2728
#ifdef HAVE_SYS_SELECT_H
2829
#include <sys/select.h>
@@ -4107,7 +4108,7 @@ PostgresMain(int argc, char *argv[], const char *username)
41074108
/*
41084109
* Obtain platform stack depth limit (in bytes)
41094110
*
4110-
* Return -1 if unlimited or not known
4111+
* Return -1 if unknown
41114112
*/
41124113
long
41134114
get_stack_depth_rlimit(void)
@@ -4123,7 +4124,10 @@ get_stack_depth_rlimit(void)
41234124
if (getrlimit(RLIMIT_STACK, &rlim) < 0)
41244125
val = -1;
41254126
else if (rlim.rlim_cur == RLIM_INFINITY)
4126-
val = -1;
4127+
val = LONG_MAX;
4128+
/* rlim_cur is probably of an unsigned type, so check for overflow */
4129+
else if (rlim.rlim_cur >= LONG_MAX)
4130+
val = LONG_MAX;
41274131
else
41284132
val = rlim.rlim_cur;
41294133
}

src/backend/utils/misc/guc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3485,14 +3485,14 @@ InitializeGUCOptions(void)
34853485
stack_rlimit = get_stack_depth_rlimit();
34863486
if (stack_rlimit > 0)
34873487
{
3488-
int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
3488+
long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
34893489

34903490
if (new_limit > 100)
34913491
{
34923492
char limbuf[16];
34933493

34943494
new_limit = Min(new_limit, 2048);
3495-
sprintf(limbuf, "%d", new_limit);
3495+
sprintf(limbuf, "%ld", new_limit);
34963496
SetConfigOption("max_stack_depth", limbuf,
34973497
PGC_POSTMASTER, PGC_S_ENV_VAR);
34983498
}

src/test/regress/expected/plpgsql.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4006,7 +4006,7 @@ $$ language plpgsql;
40064006
-- "limit" is to prevent this from being inlined
40074007
create function sql_recurse(float8) returns float8 as
40084008
$$ select recurse($1) limit 1; $$ language sql;
4009-
select recurse(5);
4009+
select recurse(10);
40104010
recurse
40114011
---------
40124012
0

src/test/regress/sql/plpgsql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3211,7 +3211,7 @@ $$ language plpgsql;
32113211
create function sql_recurse(float8) returns float8 as
32123212
$$ select recurse($1) limit 1; $$ language sql;
32133213

3214-
select recurse(5);
3214+
select recurse(10);
32153215

32163216
create function error1(text) returns text language sql as
32173217
$$ SELECT relname::text FROM pg_class c WHERE c.oid = $1::regclass $$;

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