Skip to content

UnpickleableException.dump blows up when exception comes from setuptools #440

@ghost

Description

Originally reported by: embray (Bitbucket: embray, GitHub: embray)


Another odd one, but pretty bad.

I've found that sometimes when running setuptools.sandbox.run_setup, if an exception occurs in the setup like SandboxViolation, when the ExceptionSaver tries to pickle it it will fail because of:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/setuptools/sandbox.py", line 108, in dump
    return pickle.dumps(type), pickle.dumps(exc)
_pickle.PicklingError: Can't pickle <class 'setuptools.sandbox.SandboxViolation'>: it's not the same object as setuptools.sandbox.SandboxViolation

The code, as written, then just tries to repr the exception and wrap in the an UnpickleableException and then pickle that. But that fails too for the same reason:

  File "/usr/local/lib/python3.4/site-packages/setuptools/sandbox.py", line 242, in run_setup
    raise
  File "/usr/local/lib/python3.4/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.4/site-packages/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/usr/local/lib/python3.4/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.4/site-packages/setuptools/sandbox.py", line 154, in save_modules
    yield saved
  File "/usr/local/lib/python3.4/site-packages/setuptools/sandbox.py", line 128, in __exit__
    self._saved = UnpickleableException.dump(type, exc)
  File "/usr/local/lib/python3.4/site-packages/setuptools/sandbox.py", line 112, in dump
    return cls.dump(cls, cls(repr(exc)))
  File "/usr/local/lib/python3.4/site-packages/setuptools/sandbox.py", line 108, in dump
    return pickle.dumps(type), pickle.dumps(exc)
_pickle.PicklingError: Can't pickle <class 'setuptools.sandbox.UnpickleableException'>: it's not the same object as setuptools.sandbox.UnpickleableException

This occurs because by the time ExceptionSaver.__exit__ is entered, the hide_setuptools has occurred and there are two copies of the setuptools.sandbox module in play, basically.

This actually tends to lead to a MemoryError before a recursion RuntimeError is reached due to the resulting exponential growth in the size of repr(exc) :(


Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions