Content-Length: 260434 | pFad | https://github.com/python/cpython/issues/98458

AB Unittest: self-referencing explicit exception cause results in infinite loop · Issue #98458 · python/cpython · GitHub
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

Unittest: self-referencing explicit exception cause results in infinite loop #98458

Closed
AlexTate opened this issue Oct 19, 2022 · 1 comment · Fixed by #98459
Closed

Unittest: self-referencing explicit exception cause results in infinite loop #98458

AlexTate opened this issue Oct 19, 2022 · 1 comment · Fixed by #98459
Labels
type-bug An unexpected behavior, bug, or error

Comments

@AlexTate
Copy link
Contributor

AlexTate commented Oct 19, 2022

Bug report

If an exception is raised with a self-referencing __cause__ or __context__ then TestResult._clean_tracebacks() in result.py enters an infinite loop.

Minimal example 1:

try:
    raise Exception()
except Exception as e:
    raise e from e

Minimal example 2:

try:
    e = Exception()
    raise e from e
except Exception as e:
    raise e

Identified Cause

Self-references are not checked while unwinding the chained exception on line 216 of result.py

Your environment

  • CPython versions tested on: 3.9, 3.10
  • Operating system and architecture: macOS

Linked PRs

@AlexTate AlexTate added the type-bug An unexpected behavior, bug, or error label Oct 19, 2022
gpshead pushed a commit that referenced this issue Dec 4, 2022
…xceptions that contain cycles (#98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 4, 2022
…ined exceptions that contain cycles (pythonGH-98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
(cherry picked from commit 72ec518)

Co-authored-by: AlexTate <0xalextate@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 4, 2022
…ined exceptions that contain cycles (pythonGH-98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
(cherry picked from commit 72ec518)

Co-authored-by: AlexTate <0xalextate@gmail.com>
@gpshead
Copy link
Member

gpshead commented Dec 4, 2022

Thanks! A bit of an unusual issue but no doubt a pain to debug when something winds up with this happening.
The backport PRs should automerge after CI runs.

miss-islington added a commit that referenced this issue Dec 4, 2022
…xceptions that contain cycles (GH-98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
(cherry picked from commit 72ec518)

Co-authored-by: AlexTate <0xalextate@gmail.com>
miss-islington added a commit that referenced this issue Dec 4, 2022
…xceptions that contain cycles (GH-98459)

* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
(cherry picked from commit 72ec518)

Co-authored-by: AlexTate <0xalextate@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python/cpython/issues/98458

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy