Skip to content

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

Closed

Description

@AlexTate

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

Activity

  1. added a commit that references this issue on Dec 4, 2022
  2. added 2 commits that reference this issue on Dec 4, 2022
  3. gpshead commented on Dec 4, 2022

    @gpshead
    Member

    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.

  4. added 2 commits that reference this issue on Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions