Skip to content

Commit

Permalink
bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546)
Browse files Browse the repository at this point in the history
Under some conditions the earlier fix for bpo-18075, "Infinite recursion
tests triggering a segfault on Mac OS X", now causes failures on macOS
when attempting to change stack limit with resource.setrlimit
resource.RLIMIT_STACK, like regrtest does when running the test suite.
The reverted change had specified a non-default stack size when linking
the python executable on macOS.  As of macOS 10.14.4, the previous
code causes a hard failure when running tests, although similar
failures had been seen under some conditions under some earlier
systems.  Reverting the change to the interpreter stack size at link
time helped for release builds but caused some tests to fail when
built --with-pydebug.  Try the opposite approach: continue to build
the interpreter with an increased stack size on macOS and remove
the failing setrlimit call in regrtest initialization.  This will
definitely avoid the resource.RLIMIT_STACK error and should have
no, or fewer, side effects.
(cherry picked from commit 5bbbc73)

Co-authored-by: Ned Deily <nad@python.org>
  • Loading branch information
miss-islington and ned-deily committed Jul 2, 2019
1 parent 6348364 commit dcc0eb3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 0 additions & 16 deletions Lib/test/libregrtest/setup.py
Expand Up @@ -58,22 +58,6 @@ def setup_tests(ns):
if getattr(module, '__file__', None):
module.__file__ = os.path.abspath(module.__file__)

# MacOSX (a.k.a. Darwin) has a default stack size that is too small
# for deeply recursive regular expressions. We see this as crashes in
# the Python test suite when running test_re.py and test_sre.py. The
# fix is to set the stack limit to 2048.
# This approach may also be useful for other Unixy platforms that
# suffer from small default stack limits.
if sys.platform == 'darwin':
try:
import resource
except ImportError:
pass
else:
soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
newsoft = min(hard, max(soft, 1024*2048))
resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))

if ns.huntrleaks:
unittest.BaseTestSuite._cleanup = False

Expand Down
@@ -0,0 +1,4 @@
Avoid test suite failures on macOS by no longer calling resource.setrlimit
to increase the process stack size limit at runtime. The runtime change is
no longer needed since the interpreter is being built with a larger default
stack size.
6 changes: 6 additions & 0 deletions configure
Expand Up @@ -9541,6 +9541,12 @@ then
# -u libsys_s pulls in all symbols in libsys
Darwin/*)
LINKFORSHARED="$extra_undefs -framework CoreFoundation"

# Issue #18075: the default maximum stack size (8MBytes) is too
# small for the default recursion limit. Increase the stack size
# to ensure that tests don't crash
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"

if test "$enable_framework"
then
LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Expand Up @@ -2708,6 +2708,12 @@ then
# -u libsys_s pulls in all symbols in libsys
Darwin/*)
LINKFORSHARED="$extra_undefs -framework CoreFoundation"

# Issue #18075: the default maximum stack size (8MBytes) is too
# small for the default recursion limit. Increase the stack size
# to ensure that tests don't crash
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"

if test "$enable_framework"
then
LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
Expand Down

0 comments on commit dcc0eb3

Please sign in to comment.