classification
Title: Infinite recursion tests triggering a segfault
Type: crash Stage: patch review
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: brett.cannon, larry, miss-islington, ned.deily, python-dev, ronaldoussoren, vstinner
Priority: release blocker Keywords:

Created on 2013-05-28 01:02 by brett.cannon, last changed 2019-07-02 22:34 by ned.deily. This issue is now closed.

Files
File name Uploaded Description Edit
issue-18075-osx-stacksize.txt ronaldoussoren, 2013-05-28 12:31 review
issue-18075-osx-stacksize-update.txt ronaldoussoren, 2013-05-28 13:20 review
Pull Requests
URL Status Linked Edit
PR 13011 merged ned.deily, 2019-04-29 18:48
PR 13013 merged miss-islington, 2019-04-29 19:08
PR 13014 merged miss-islington, 2019-04-29 19:32
PR 14546 merged ned.deily, 2019-07-02 06:55
PR 14547 merged miss-islington, 2019-07-02 07:12
PR 14548 merged miss-islington, 2019-07-02 07:12
PR 14549 merged miss-islington, 2019-07-02 07:13
Messages (18)
msg190162 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-05-28 01:02
If you run any test that has infinite recursion (test_json test_exceptions test_sys test_runpy) it will segfault with a fresh checkout under OS X 10.8.3 using Clang. Not sure how widespread this is.

I did check that I am using a clean checkout of the default branch.
msg190192 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-28 10:23
I can confirm the problem. It appears to be a stack overflow, when I increase the stack size of the main thead (by adding "-Wl,-stack_size,2faf000" to the link command for BUILDPYTHON) the crash in test_json goes away.

Appearently the default maximum stack size isn't large enough for the default value of the recursion limit.

An easy workaround (fix?) would be to add -Wl,-stack_size,VALUE to the link flags on OSX, for some sane value of VALUE. The value is the maximum size of the stack of the main thread and doesn't affect process size unless a process actually uses more stack space. It does affect the available free address space, and hence the maximum stack size shouldn't be increased too far (especially for 32-bit builds)
msg190200 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-28 12:31
The attached patch fixes the problem on OSX by increasing the maximum stack size of the main thread from 8M (the default) to 16M. 

NOTE: The -Wl,-stack_size,... option cannot be added to LDFLAGS, ld errors out when that option is used when linking a shared library (such as the extensions or libpython.dylib)
msg190205 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-28 13:20
The update fixes the name error mention in rietveld.
msg190206 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-05-28 13:26
LGTM
msg190354 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-05-30 11:49
> Appearently the default maximum stack size isn't large enough for the default value of the recursion limit.

Why not changing the recursion limit instead of the size of the stack?
msg190355 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-30 12:18
I'd prefer to keep the default recursion limit the same as on Linux, changing the recursion limit on OSX would just introduce an unnecessary difference between the two platforms.

The patch changes the maximum stack size from 8 to 16 MByte, neither of which is huge and shouldn't cause other problems.

I'd also like to increase the default stack size for newly created threads (see #18049) and will update that patch to create a 16 MByte stack as well.
msg190356 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-05-30 12:50
> The patch changes the maximum stack size from 8 to 16 MByte, neither of which is huge and shouldn't cause other problems.

On Mac OS X: Is the memory allocated at Python startup, or on demand,
as the stack grows? If I am correct, the physical memory is allocated
on demand on Linux.

2013/5/30 Ronald Oussoren <report@bugs.python.org>:
>
> Ronald Oussoren added the comment:
>
> I'd prefer to keep the default recursion limit the same as on Linux, changing the recursion limit on OSX would just introduce an unnecessary difference between the two platforms.
>
> The patch changes the maximum stack size from 8 to 16 MByte, neither of which is huge and shouldn't cause other problems.
>
> I'd also like to increase the default stack size for newly created threads (see #18049) and will update that patch to create a 16 MByte stack as well.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue18075>
> _______________________________________
msg190358 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-30 13:33
On 30 May, 2013, at 14:50, STINNER Victor <report@bugs.python.org> wrote:

> 
> STINNER Victor added the comment:
> 
>> The patch changes the maximum stack size from 8 to 16 MByte, neither of which is huge and shouldn't cause other problems.
> 
> On Mac OS X: Is the memory allocated at Python startup, or on demand,
> as the stack grows? If I am correct, the physical memory is allocated
> on demand on Linux.

Memory for the stack is allocated on demand, the parameter sets the maximum size that the stack can grow to. See also man ld(1).

Ronald
msg190378 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-05-30 19:02
New changeset b07ad4b5e349 by Łukasz Langa in branch 'default':
Fixed #18075 - Infinite recursion tests triggering a segfault on Mac OS X
http://hg.python.org/cpython/rev/b07ad4b5e349
msg341111 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-04-29 19:07
New changeset 883dfc668f9730b00928730035b5dbd24b9da2a0 by Ned Deily in branch 'master':
bpo-34602: Avoid failures setting macOS stack resource limit (GH-13011)
https://github.com/python/cpython/commit/883dfc668f9730b00928730035b5dbd24b9da2a0
msg341113 - (view) Author: miss-islington (miss-islington) Date: 2019-04-29 19:27
New changeset 52a5b71063af68c42b048095c4e555e93257f151 by Miss Islington (bot) in branch '3.7':
bpo-34602: Avoid failures setting macOS stack resource limit (GH-13011)
https://github.com/python/cpython/commit/52a5b71063af68c42b048095c4e555e93257f151
msg341117 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-04-29 19:57
New changeset fbe2a1394bf52f5a4455681e1b1f705a31559585 by Ned Deily (Miss Islington (bot)) in branch '3.6':
bpo-34602: Avoid failures setting macOS stack resource limit (GH-13011) (GH-13014)
https://github.com/python/cpython/commit/fbe2a1394bf52f5a4455681e1b1f705a31559585
msg347112 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-07-02 07:12
New changeset 5bbbc733e6cc0804f19b071944af8d4719e26ae6 by Ned Deily in branch 'master':
bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546)
https://github.com/python/cpython/commit/5bbbc733e6cc0804f19b071944af8d4719e26ae6
msg347114 - (view) Author: miss-islington (miss-islington) Date: 2019-07-02 07:31
New changeset bd92b94da93198c8385c06ca908407f172c7e8b2 by Miss Islington (bot) in branch '3.8':
bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546)
https://github.com/python/cpython/commit/bd92b94da93198c8385c06ca908407f172c7e8b2
msg347116 - (view) Author: miss-islington (miss-islington) Date: 2019-07-02 07:38
New changeset bf82cd3124df94935c6e3190c7c40b76918d2174 by Miss Islington (bot) in branch '3.7':
bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546)
https://github.com/python/cpython/commit/bf82cd3124df94935c6e3190c7c40b76918d2174
msg347118 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-07-02 07:49
New changeset 782854f90ad5f73f787f68693d535f2b05514e13 by Ned Deily (Miss Islington (bot)) in branch '3.6':
bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546) (GH-14549)
https://github.com/python/cpython/commit/782854f90ad5f73f787f68693d535f2b05514e13
msg347166 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-07-02 22:34
New changeset dcc0eb379613f279864af61023ea44c94aa0535c by Ned Deily (Miss Islington (bot)) in branch '3.7':
bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546)
https://github.com/python/cpython/commit/dcc0eb379613f279864af61023ea44c94aa0535c
History
Date User Action Args
2019-07-02 22:34:03ned.deilysetmessages: + msg347166
2019-07-02 07:49:02ned.deilysetmessages: + msg347118
2019-07-02 07:38:41miss-islingtonsetmessages: + msg347116
2019-07-02 07:31:12miss-islingtonsetmessages: + msg347114
2019-07-02 07:13:05miss-islingtonsetpull_requests: + pull_request14366
2019-07-02 07:12:52miss-islingtonsetpull_requests: + pull_request14364
2019-07-02 07:12:43miss-islingtonsetpull_requests: + pull_request14362
2019-07-02 07:12:37ned.deilysetmessages: + msg347112
2019-07-02 06:55:43ned.deilysetpull_requests: + pull_request14360
2019-06-21 18:35:45ned.deilylinkissue37365 superseder
2019-04-29 19:57:20ned.deilysetmessages: + msg341117
2019-04-29 19:32:07miss-islingtonsetpull_requests: + pull_request12937
2019-04-29 19:27:39miss-islingtonsetnosy: + miss-islington
messages: + msg341113
2019-04-29 19:08:00miss-islingtonsetpull_requests: + pull_request12935
2019-04-29 19:07:44ned.deilysetnosy: + ned.deily
messages: + msg341111
2019-04-29 18:48:20ned.deilysetpull_requests: + pull_request12933
2013-05-30 19:31:46lukasz.langasetstatus: open -> closed
resolution: fixed
2013-05-30 19:02:29python-devsetnosy: + python-dev
messages: + msg190378
2013-05-30 13:33:40ronaldoussorensetmessages: + msg190358
2013-05-30 12:50:20vstinnersetmessages: + msg190356
2013-05-30 12:18:35ronaldoussorensetmessages: + msg190355
2013-05-30 11:49:08vstinnersetnosy: + vstinner
messages: + msg190354
2013-05-28 13:26:36brett.cannonsetassignee: ronaldoussoren
messages: + msg190206
2013-05-28 13:20:37ronaldoussorensetfiles: + issue-18075-osx-stacksize-update.txt

messages: + msg190205
2013-05-28 12:31:27ronaldoussorensetfiles: + issue-18075-osx-stacksize.txt

messages: + msg190200
stage: patch review
2013-05-28 10:23:38ronaldoussorensetnosy: + ronaldoussoren
messages: + msg190192
2013-05-28 01:02:08brett.cannoncreate