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

pickling of large recursive structures crashes cPickle #46954

Closed
cyhawk mannequin opened this issue Apr 27, 2008 · 15 comments
Closed

pickling of large recursive structures crashes cPickle #46954

cyhawk mannequin opened this issue Apr 27, 2008 · 15 comments
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@cyhawk
Copy link
Mannequin

cyhawk mannequin commented Apr 27, 2008

BPO 2702
Nosy @loewis, @facundobatista, @jcea, @amauryfa, @bkline, @avassalotti
Files
  • bugdemo.py: causes silent termination ("ok" is not printed) on my computer
  • test_cpickle.diff: Patch to the tests, to raise this issue
  • cpickle.patch
  • cpickle2.patch: use Py_EnterRecursiveCall instead of self->nesting
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-06-30.01:11:29.849>
    created_at = <Date 2008-04-27.07:53:07.805>
    labels = ['library', 'type-crash']
    title = 'pickling of large recursive structures crashes cPickle'
    updated_at = <Date 2008-07-16.16:35:27.046>
    user = 'https://bugs.python.org/cyhawk'

    bugs.python.org fields:

    activity = <Date 2008-07-16.16:35:27.046>
    actor = 'facundobatista'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-06-30.01:11:29.849>
    closer = 'facundobatista'
    components = ['Library (Lib)']
    creation = <Date 2008-04-27.07:53:07.805>
    creator = 'cyhawk'
    dependencies = []
    files = ['10119', '10701', '10737', '10738']
    hgrepos = []
    issue_num = 2702
    keywords = ['patch']
    message_count = 15.0
    messages = ['65876', '65878', '65879', '68587', '68588', '68589', '68591', '68601', '68745', '68759', '68760', '68764', '68982', '69761', '69799']
    nosy_count = 9.0
    nosy_names = ['loewis', 'facundobatista', 'jcea', 'esrever_otua', 'amaury.forgeotdarc', 'bkline', 'alexandre.vassalotti', 'schmir', 'cyhawk']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue2702'
    versions = ['Python 2.5']

    @cyhawk
    Copy link
    Mannequin Author

    cyhawk mannequin commented Apr 27, 2008

    The documentation1 says:

    Trying to pickle a highly recursive data structure may exceed the
    maximum recursion depth, a RuntimeError will be raised in this
    case. You can carefully raise this limit with sys.setrecursionlimit().

    The lightweight pickle module handles this problem correctly (in that it
    raises a RuntimeError), but cPickle sometimes raises KeyError instead,
    or just silently terminates the interpreter (=crashes). (I have not been
    able to pinpoint what it depends on. In the attached example I get
    silent termination, but if instead of lists I use sets to describe the
    connections, I get the RuntimeError.)

    This was mentioned in bpo-2480, but that has now been changed to a
    feature request to eliminate recursion altogether. That may have a lower
    priority, but this crash can be hard to diagnose in a complex
    application, and I am not sure if sys.setrecursionlimit() affects
    cPickle behavior (I guess not).

    @cyhawk cyhawk mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Apr 27, 2008
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Apr 27, 2008

    What operating system and compiler are you using?

    @cyhawk
    Copy link
    Mannequin Author

    cyhawk mannequin commented Apr 27, 2008

    Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
    (Intel)] on win32

    (Windows XP Professional 32 bits)

    @facundobatista
    Copy link
    Member

    Could you please tell me if this problem arises with this test?

    @cyhawk
    Copy link
    Mannequin Author

    cyhawk mannequin commented Jun 22, 2008

    I have just quickly pasted it into an interpreter.

    Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
    (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class Node(object):
    ...     pass
    ...
    >>> nodes = [Node() for i in range(500)]
    >>> for n in nodes:
    ...     n.connections = list(nodes)
    ...     n.connections.remove(n)
    ...
    >>> import cPickle
    >>> s = cPickle.dumps( n )

    After this line, the interpreter terminated without any further output
    (no Python exception and no Windows "General Exception" message box either).

    Is it sufficient, or would you prefer me to run the test properly?

    @facundobatista
    Copy link
    Member

    Daniel, it'd be great, because it does not crash in linux, so I can not
    test it... and I have a patch to apply (see bpo-3165), so I wanted to
    test it that way.

    @cyhawk
    Copy link
    Mannequin Author

    cyhawk mannequin commented Jun 22, 2008

    It works for me as a test case too:

    test_deep_recursive (main.cPickleDeepRecursive) ... ERROR

    ======================================================================
    ERROR: test_deep_recursive (main.cPickleDeepRecursive)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "c:\devel\Python25\Lib\test\test_cpickle.py", line 107, in
    test_deep_recursive
        self.assertRaises(RuntimeError, cPickle.dumps, n)
      File "C:\devel\Python25\lib\unittest.py", line 320, in failUnlessRaises
        callableObj(*args, **kwargs)
    KeyError: 13352688

    @facundobatista
    Copy link
    Member

    Commited this patch to the test cases, and the patch from bpo-3165 to fix
    the problem, thank you all!

    @facundobatista
    Copy link
    Member

    I reverted the patch, because of bpo-3179, so I'm reopening this.

    Note that I left the test in the suite, but commented out (if you find a
    patch that solves this, activate the test again).

    @amauryfa
    Copy link
    Member

    It seems that each self->nesting++ should be balanced with
    self->nesting--. Attached patch enables all tests and corrects the issue

    @amauryfa
    Copy link
    Member

    Another version of the patch, that removes the self->nesting member and
    uses the Py_EnterRecursiveCall machinery.
    I prefer it because it takes into account the depth of the current
    python call stack.

    @schmir
    Copy link
    Mannequin

    schmir mannequin commented Jun 26, 2008

    The tests pass on my machine (64 bit debian testing) with cpickle2.patch.

    @facundobatista
    Copy link
    Member

    Great, Amaury, I applied your second patch... it make all tests pass ok, :)

    Commited in 64595.

    Thank you all!!

    @esreverotua
    Copy link
    Mannequin

    esreverotua mannequin commented Jul 16, 2008

    Please check issue bpo-3338 for a dup of this issue with a testcase that
    continues to fail after the application of r64595

    @facundobatista
    Copy link
    Member

    Thanks Darryl.

    We'll continue in that issue, as the patched commited in this one did
    not introduce a regression (it just didn't fix the other bug also).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants