Skip to content
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

Segmentation fault on major GC collection if GC hooks are installed #4899

Closed
Yevhenii-Yatchenko opened this issue Feb 16, 2024 · 6 comments
Closed

Comments

@Yevhenii-Yatchenko
Copy link

Dears,

I've noticed a segmentation fault if GC hooks are installed.

STR:

  1. Install GC hooks according to https://doc.pypy.org/en/latest/gc_info.html

  2. Load the interpreter with some data operations to trigger GC Major collection.

> pypy3.6-gdb 1.py
PyPy assertion failed at rpython_memory_gc.c:5149:
in pypy_g_IncrementalMiniMarkGC_collect_oldrefs_to_nursery: old_objects_pointing_to_young contains obj with GCFLAG_TRACK_YOUNG_PTRS
Aborted (core dumped)

  1. Process dies with a core dump.

PyPy version:

> pypy3.6-gdb
Python 3.6.9 (6c09c80243d4, Feb 15 2024, 20:40:35)
[PyPy 7.3.1 with GCC 12.2.1 20221121 (Red Hat 12.2.1-7.4.0.2)] on linux

The code that reproduces the issue:

import gc
import random
from time import sleep


class _Hooks:

    def on_gc_minor(self, *args, **kwargs):
        pass

    def on_gc_collect_step(self, *args, **kwargs):
        pass

    def on_gc_collect(self, *args, **kwargs):
        pass


gc.hooks.set(_Hooks())


def getRandomString(length):
    return ','.join([random.choice('abc') for _ in range(length)])


def doJob():
    a = ''
    for _ in range(1000):
        a = getRandomString(100)

    return a

counter = 0
while True:
    counter += 0

    doJob()

    sleep(1)
    print(counter)

Please let me know if additional info is required.

@Yevhenii-Yatchenko
Copy link
Author

Attaching a file with the bt from coredump.
coredump_bt.txt

@devdanzin
Copy link
Contributor

I can't reproduce with the official 7.3.1 build from https://downloads.python.org/pypy/pypy3.6-v7.3.1-linux64.tar.bz2 on WSL (Ubuntu), can you?

Python 3.6.9 (2ad108f17bdb, Apr 07 2020, 02:59:05)
[PyPy 7.3.1 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] on linux

Maybe it only triggers on debug builds?

@cfbolz
Copy link
Member

cfbolz commented Feb 18, 2024

Maybe it only triggers on debug builds?

the backtrace shows an RPyAssertFailed, so yes, this would only trigger during debug builds.

@Yevhenii-Yatchenko
Copy link
Author

I tried locally with the proposed PyPy binary and the one I had before - I can not reproduce this issue if the interpreter is built without debug headers.

But if debug headers are present - we need to choose between using hooks or trying to get the actual core dump, for which the debug headers were added.

@cfbolz cfbolz closed this as completed in df780ed Feb 19, 2024
cfbolz added a commit that referenced this issue Feb 19, 2024
@cfbolz cfbolz reopened this Feb 19, 2024
@cfbolz
Copy link
Member

cfbolz commented Feb 19, 2024

OK, the above PR should fix this issue on pypy2. Will merge into the 3.9 and 3.10 branches as soon as my home internet gets fixed.

@mattip
Copy link
Member

mattip commented Apr 24, 2024

Closing since the 7.3.16 release has this fix. Please reopen if I misunderstood

@mattip mattip closed this as completed Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants