-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfaults in cypari2 when running out of stack during deep object deallocation #27267
Comments
comment:1
I have no further information to add at this point, but CC-ing you in case anything about this is obvious to you. |
comment:2
Are these problems reproducible? Do they occur when running the tests individually? It would also be good to know the precise value of the pari stack size ( |
comment:3
It's completely reproducible and deterministic, at least when running the test suite. I haven't tried putting together a simpler way to reproduce it. But it was definitely introduced by #26442, and it's caused by an infinite recursion, apparently, in
|
comment:4
Would it be possible to check if it's an infinite recursion or just a very deep recursion, for example by increasing the process stack size (if this is possible on Cygwin)? GC is known to introduce deep-but-finite recursions (the Python trashcan mechanism was invented to deal with that). |
comment:6
Confirmed on Linux with |
Upstream: Reported upstream. Developers acknowledge bug. |
comment:8
Digging deep in the CPython trashcan mechanism... |
comment:9
Ideally, this would be fixed by Cython upstream in cython/cython#2842 |
comment:10
This all seems interesting and I want to take a closer look. But fixing this issue obviously cannot rely, at least in the short term, on both a patch to CPython and a new feature in Cython. That begins to feel like there must be a simpler approach by just reworking how cypari2 is handling these deallocations. |
comment:11
Just for the record: the fix does not depend on the CPython patch. The CPython patch is meant to fix an issue in the trashcan when subclassing is involved. But the trashcan would work without that patch. |
comment:12
And yes, this could be fixed without any Cython patch but I'd rather not bother. |
comment:13
Regardless, it's quite an integration hassle to depend on a new feature in Cython which does not exist yet, and a new release of Cython, in order to build this in such a way that it does not easily cause stack overflows. I'd rather revert the upgrade to cypari2 until this can be resolved. |
comment:14
Replying to @jdemeyer:
It depends on what you mean by "subclassing is involved". In this case subclassing is involved, as |
comment:15
Would it be possible (as interim work-around) to run Sage with a larger stack size ( |
comment:16
With "subclassing is involved", I mean more precisely a class inheriting from a base class, where the base class uses the trashcan. This is broken in CPython (for example, for subclasses of |
comment:17
I did a build of Python 2 with a 16 MB stack for the Python executable, and it fixed some of the segfaulting tests, but not others. E.g.
Among others. What should the stack size be so that this doesn't blow up? 16MB seems like plenty... |
comment:18
Replying to @jdemeyer:
I see that now. Would a class that uses |
comment:19
Replying to @jdemeyer:
Setting |
comment:20
Changed title since this does not just affect Cygwin. |
comment:21
On Linux (at least the laptop that I'm writing this on), the default stack size is 8MB. So either programs under Cygwin use much more stack or there is indeed something else. |
comment:22
Replying to @embray:
The current Cython PR uses the same code that I proposed to CPython. So yes, it works around that bug. |
comment:23
The Cython PR is merged. |
Changed upstream from Reported upstream. Developers acknowledge bug. to Fixed upstream, but not in a stable release. |
This comment has been minimized.
This comment has been minimized.
comment:39
Replying to @jdemeyer:
What about |
comment:40
And also try |
comment:41
And |
Author: Jeroen Demeyer |
This comment has been minimized.
This comment has been minimized.
Commit: |
comment:45
I'm a little confused by the attached tarball. Is a Cython upgrade needed for this, or just applying the patch? |
comment:46
Replying to @embray:
No, only the patch is needed. But I thought that it would make sense to upgrade from 0.29.2 to 0.29.5 while we're updating Cython anyway. |
comment:47
I've confirmed to my satisfaction that this does fix the recursion depth issue with deallocations. The I just want to do one run of the full test suite to ensure that no other new failures occur, but otherwise this LGTM. |
comment:48
Opened #27335 for the |
comment:49
I just upgraded my Linux build to 8.7.beta5 and now I'm getting this crash in tons of places, even with
without even having to try. I will try rebasing this ticket on 8.7.beta5 and resuming... I'm pretty satisfied now that it works on Cygwin as well. |
Changed keywords from none to upgrade, cypari2 |
comment:50
Adding "upgrade" to keywords so release manager knows to upload tarball. |
comment:51
(this comment is only triggered by the mention of I know of at least one place where cpython's trashcan is necessary in sagelib: for entries in |
comment:52
For the sake of supporting distributions, we should wait until Cython 3.0 is actually released before we use |
Reviewer: Erik Bray |
comment:54
Replying to @jdemeyer:
I agree, but how does that impact cypari2 which is a dependency of Sage anyways? |
comment:55
Replying to @embray:
This ticket adds patches for both cypari2 and Cython. Distros will probably add patches to neither. Both are acceptable. |
Changed branch from u/jdemeyer/segfaults_in_cypari2_when_running_out_of_stack_during_deep_object_deallocation to |
Since cypari2-2 (#26442), the
__dealloc__
forGen
may cause deep (but finite) recursions, causing a stack overflow. This happens in particular on Cygwin which has a smallish stack by default (and maybe it also uses more stack space?) but it can be provoked easily on other systems too withFor reference, this is the test failure on Cygwin:
It turns out that CPython's "trashcan" mechanism was precisely designed to solve this problem. So we added support upstream in Cython for
@cython.trashcan
and then use that in cypari2. While we're at it, we upgrade to the latest Cython releaseTarball: https://files.pythonhosted.org/packages/e0/31/4a166556f92c469d8291d4b03a187f325c773c330fffc1e798bf83d947f2/Cython-0.29.5.tar.gz
Upstream tickets:
Upstream: Fixed upstream, but not in a stable release.
CC: @jdemeyer
Component: packages: standard
Keywords: upgrade, cypari2
Author: Jeroen Demeyer
Branch/Commit:
b6ea17e
Reviewer: Erik Bray
Issue created by migration from https://trac.sagemath.org/ticket/27267
The text was updated successfully, but these errors were encountered: