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

Assertion failure on interrupt when catching exception group #102056

Closed
chgnrdv opened this issue Feb 19, 2023 · 3 comments · Fixed by #102078
Closed

Assertion failure on interrupt when catching exception group #102056

chgnrdv opened this issue Feb 19, 2023 · 3 comments · Fixed by #102078
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@chgnrdv
Copy link
Contributor

chgnrdv commented Feb 19, 2023

This (maybe too made-up and detached from reality) repro causes assertion failure when executed on current main (32df540).
On 3.11 it warns about "lost sys.stderr" and terminates.

import time
import threading
import _thread

def f():
    try:
        f()
    except RecursionError:
        f()

def g():
    try:
        raise ValueError()
    except* ValueError:
        f()

def h():
    time.sleep(1)
    _thread.interrupt_main()

t = threading.Thread(target=h)
t.start()
g()
t.join()

Output:

python: Objects/typeobject.c:4183: _PyType_Lookup: Assertion `!PyErr_Occurred()' failed.
Aborted (core dumped)

Stack trace:

#0  0x00007ffff7d3f34c in __pthread_kill_implementation () from /usr/lib/libc.so.6
#1  0x00007ffff7cf24b8 in raise () from /usr/lib/libc.so.6
#2  0x00007ffff7cdc534 in abort () from /usr/lib/libc.so.6
#3  0x00007ffff7cdc45c in __assert_fail_base.cold () from /usr/lib/libc.so.6
#4  0x00007ffff7ceb116 in __assert_fail () from /usr/lib/libc.so.6
#5  0x000055555574ecd9 in _PyType_Lookup (type=type@entry=0x555555be5430, name=name@entry=0x555555bb7c10 <_PyRuntime+334480>)
    at Objects/typeobject.c:4183
#6  0x00005555557319e3 in _PyObject_GenericGetAttrWithDict (obj=0x7ffff77a7c90, name=0x555555bb7c10 <_PyRuntime+334480>, dict=dict@entry=0x0, 
    suppress=suppress@entry=1) at Objects/object.c:1266
#7  0x0000555555731d8d in _PyObject_LookupAttr (v=0x7ffff77a7c90, name=<optimized out>, result=result@entry=0x7ffffff40780) at Objects/object.c:933
#8  0x000055555582764c in print_exception_file_and_line (ctx=ctx@entry=0x7fffffffe270, value_p=value_p@entry=0x7ffffff40808)
    at Python/pythonrun.c:941
#9  0x0000555555827ed2 in print_exception (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff77a7c90) at Python/pythonrun.c:1209
#10 0x0000555555827fcc in print_exception_group (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff77a7c90) at Python/pythonrun.c:1377
#11 0x0000555555828418 in print_exception_recursive (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff77a7c90) at Python/pythonrun.c:1491
#12 0x0000555555828491 in print_chained (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff77a7c90, 
    message=message@entry=0x55555594b200 <context_message> "During handling of the above exception, another exception occurred:\n", 
    tag=tag@entry=0x5555558deda0 "context") at Python/pythonrun.c:1254
#13 0x000055555582868e in print_exception_cause_and_context (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff780e900)
    at Python/pythonrun.c:1344
#14 0x00005555558283d3 in print_exception_recursive (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff780e900) at Python/pythonrun.c:1482
#15 0x0000555555828491 in print_chained (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff780e900, 
    message=message@entry=0x55555594b200 <context_message> "During handling of the above exception, another exception occurred:\n", 
    tag=tag@entry=0x5555558deda0 "context") at Python/pythonrun.c:1254

...

#16186 0x000055555582868e in print_exception_cause_and_context (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff6be0ec0)
    at Python/pythonrun.c:1344
#16187 0x00005555558283d3 in print_exception_recursive (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff6be0ec0) at Python/pythonrun.c:1482
#16188 0x0000555555828491 in print_chained (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff6be0ec0,
    message=message@entry=0x55555594b200 <context_message> "During handling of the above exception, another exception occurred:\n",
    tag=tag@entry=0x5555558deda0 "context") at Python/pythonrun.c:1254
#16189 0x000055555582868e in print_exception_cause_and_context (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff6be0f30)
    at Python/pythonrun.c:1344
#16190 0x00005555558283d3 in print_exception_recursive (ctx=ctx@entry=0x7fffffffe270, value=value@entry=0x7ffff6be0f30) at Python/pythonrun.c:1482
#16191 0x0000555555828969 in _PyErr_Display (file=file@entry=0x7ffff79ba7b0, exception=exception@entry=0x555555a75160 <_PyExc_KeyboardInterrupt>,
    value=value@entry=0x7ffff6be0f30, tb=tb@entry=0x7ffff6c22ad0) at Python/pythonrun.c:1530
#16192 0x0000555555828ad3 in PyErr_Display (exception=0x555555a75160 <_PyExc_KeyboardInterrupt>, value=0x7ffff6be0f30, tb=0x7ffff6c22ad0)
    at Python/pythonrun.c:1562
#16193 0x0000555555835660 in sys_excepthook_impl (module=module@entry=0x7ffff7947f50, exctype=<optimized out>, value=<optimized out>,
    traceback=<optimized out>) at ./Python/sysmodule.c:748
#16194 0x00005555558356c6 in sys_excepthook (module=0x7ffff7947f50, args=args@entry=0x7fffffffe3f0, nargs=nargs@entry=3)
    at ./Python/clinic/sysmodule.c.h:102
#16195 0x000055555572c28c in cfunction_vectorcall_FASTCALL (func=0x7ffff7948470, args=0x7fffffffe3f0, nargsf=<optimized out>, kwnames=<optimized out>)
    at Objects/methodobject.c:422
#16196 0x00005555556e1aa0 in _PyObject_VectorcallTstate (tstate=0x555555bd8808 <_PyRuntime+468616>, callable=callable@entry=0x7ffff7948470,
    args=0x7fffffffe3f0, args@entry=0x7fffffffe360, nargsf=nargsf@entry=3, kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:92
#16197 0x00005555556e1b90 in _PyObject_FastCallTstate (nargs=3, args=0x7fffffffe360, func=0x7ffff7948470, tstate=<optimized out>)
    at ./Include/internal/pycore_call.h:116
#16198 _PyObject_FastCall (func=func@entry=0x7ffff7948470, args=args@entry=0x7fffffffe3f0, nargs=nargs@entry=3) at Objects/call.c:310
#16199 0x0000555555828c2b in _PyErr_PrintEx (tstate=0x555555bd8808 <_PyRuntime+468616>, set_sys_last_vars=set_sys_last_vars@entry=1)
    at Python/pythonrun.c:813
#16200 0x0000555555828eb1 in PyErr_PrintEx (set_sys_last_vars=set_sys_last_vars@entry=1) at Python/pythonrun.c:861
#16201 0x0000555555828ec1 in PyErr_Print () at Python/pythonrun.c:867
#16202 0x00005555558293ab in _PyRun_SimpleFileObject (fp=fp@entry=0x555555bdb530, filename=filename@entry=0x7ffff77adbc0, closeit=closeit@entry=1,
    flags=flags@entry=0x7fffffffe508) at Python/pythonrun.c:439
#16203 0x000055555582951d in _PyRun_AnyFileObject (fp=fp@entry=0x555555bdb530, filename=filename@entry=0x7ffff77adbc0, closeit=closeit@entry=1,
    flags=flags@entry=0x7fffffffe508) at Python/pythonrun.c:78
#16204 0x00005555558487a5 in pymain_run_file_obj (program_name=program_name@entry=0x7ffff77c7370, filename=filename@entry=0x7ffff77adbc0,
    skip_source_first_line=0) at Modules/main.c:360
#16205 0x00005555558488cd in pymain_run_file (config=config@entry=0x555555bbd3c0 <_PyRuntime+356928>) at Modules/main.c:379
#16206 0x0000555555849063 in pymain_run_python (exitcode=exitcode@entry=0x7fffffffe684) at Modules/main.c:610
#16207 0x000055555584930f in Py_RunMain () at Modules/main.c:689
#16208 0x0000555555849386 in pymain_main (args=args@entry=0x7fffffffe6e0) at Modules/main.c:719
#16209 0x000055555584944c in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:743
#16210 0x0000555555651772 in main (argc=<optimized out>, argv=<optimized out>) at ./Programs/python.c:15

Linked PRs

@chgnrdv chgnrdv added the type-crash A hard crash of the interpreter, possibly with a core dump label Feb 19, 2023
@iritkatriel
Copy link
Member

You don’t get this with except?

@chgnrdv
Copy link
Contributor Author

chgnrdv commented Feb 20, 2023

As far as i can see it fails only with except* <exc_type> if exc_type matches the type of exception raised in corresponding try statement.

@iritkatriel
Copy link
Member

Thank you @chgnrdv .

carljm added a commit to carljm/cpython that referenced this issue Feb 20, 2023
* main: (60 commits)
  pythongh-102056: Fix a few bugs in error handling of exception printing code (python#102078)
  pythongh-102011: use sys.exception() instead of sys.exc_info() in docs where possible (python#102012)
  pythongh-101566: Sync with zipp 3.14. (pythonGH-102018)
  pythonGH-99818: improve the documentation for zipfile.Path and Traversable (pythonGH-101589)
  pythongh-88233: zipfile: handle extras after a zip64 extra (pythonGH-96161)
  pythongh-101981: Apply HOMEBREW related environment variables (pythongh-102074)
  pythongh-101907: Stop using `_Py_OPCODE` and `_Py_OPARG` macros (pythonGH-101912)
  pythongh-101819: Adapt _io types to heap types, batch 1 (pythonGH-101949)
  pythongh-101981: Build macOS as recommended by the devguide (pythonGH-102070)
  pythongh-97786: Fix compiler warnings in pytime.c (python#101826)
  pythongh-101578: Amend PyErr_{Set,Get}RaisedException docs (python#101962)
  Misc improvements to the float tutorial (pythonGH-102052)
  pythongh-85417: Clarify behaviour on branch cuts in cmath module (python#102046)
  pythongh-100425: Update tutorial docs related to sum() accuracy (FH-101854)
  Add missing 'is' to `cmath.log()` docstring (python#102049)
  pythongh-100210: Correct the comment link for unescaping HTML (python#100212)
  pythongh-97930: Also include subdirectory in makefile. (python#102030)
  pythongh-99735: Use required=True in argparse subparsers example (python#100927)
  Fix incorrectly documented attribute in csv docs (python#101250)
  pythonGH-84783: Make the slice object hashable (pythonGH-101264)
  ...
carljm added a commit to carljm/cpython that referenced this issue Feb 22, 2023
* main: (225 commits)
  pythongh-102056: Fix a few bugs in error handling of exception printing code (python#102078)
  pythongh-102011: use sys.exception() instead of sys.exc_info() in docs where possible (python#102012)
  pythongh-101566: Sync with zipp 3.14. (pythonGH-102018)
  pythonGH-99818: improve the documentation for zipfile.Path and Traversable (pythonGH-101589)
  pythongh-88233: zipfile: handle extras after a zip64 extra (pythonGH-96161)
  pythongh-101981: Apply HOMEBREW related environment variables (pythongh-102074)
  pythongh-101907: Stop using `_Py_OPCODE` and `_Py_OPARG` macros (pythonGH-101912)
  pythongh-101819: Adapt _io types to heap types, batch 1 (pythonGH-101949)
  pythongh-101981: Build macOS as recommended by the devguide (pythonGH-102070)
  pythongh-97786: Fix compiler warnings in pytime.c (python#101826)
  pythongh-101578: Amend PyErr_{Set,Get}RaisedException docs (python#101962)
  Misc improvements to the float tutorial (pythonGH-102052)
  pythongh-85417: Clarify behaviour on branch cuts in cmath module (python#102046)
  pythongh-100425: Update tutorial docs related to sum() accuracy (FH-101854)
  Add missing 'is' to `cmath.log()` docstring (python#102049)
  pythongh-100210: Correct the comment link for unescaping HTML (python#100212)
  pythongh-97930: Also include subdirectory in makefile. (python#102030)
  pythongh-99735: Use required=True in argparse subparsers example (python#100927)
  Fix incorrectly documented attribute in csv docs (python#101250)
  pythonGH-84783: Make the slice object hashable (pythonGH-101264)
  ...
carljm added a commit to carljm/cpython that referenced this issue Feb 23, 2023
* main: (76 commits)
  Fix syntax error in struct doc example (python#102160)
  pythongh-99108: Import MD5 and SHA1 from HACL* (python#102089)
  pythonGH-101777: `queue.rst`: use 2 spaces after a period to be consistent. (python#102143)
  Few coverage nitpicks for the cmath module (python#102067)
  pythonGH-100982: Restrict `FOR_ITER_RANGE` to a single instruction to allow instrumentation. (pythonGH-101985)
  pythongh-102135: Update turtle docs to rename wikipedia demo to rosette (python#102137)
  pythongh-99942: python.pc on android/cygwin should link to libpython per configure.ac (pythonGH-100356)
  pythongh-95672 fix typo SkitTest to SkipTest (pythongh-102119)
  pythongh-101936: Update the default value of fp from io.StringIO to io.BytesIO (pythongh-102100)
  pythongh-102008: simplify test_except_star by using sys.exception() instead of sys.exc_info() (python#102009)
  pythongh-101903: Remove obsolete undefs for previously removed macros Py_EnterRecursiveCall and Py_LeaveRecursiveCall (python#101923)
  pythongh-100556: Improve clarity of `or` docs (python#100589)
  pythongh-101777: Make `PriorityQueue` docs slightly clearer (python#102026)
  pythongh-101965: Fix usage of Py_EnterRecursiveCall return value in _bisectmodule.c (pythonGH-101966)
  pythongh-101578: Amend exception docs (python#102057)
  pythongh-101961 fileinput.hookcompressed should not set the encoding value for the binary mode (pythongh-102068)
  pythongh-102056: Fix a few bugs in error handling of exception printing code (python#102078)
  pythongh-102011: use sys.exception() instead of sys.exc_info() in docs where possible (python#102012)
  pythongh-101566: Sync with zipp 3.14. (pythonGH-102018)
  pythonGH-99818: improve the documentation for zipfile.Path and Traversable (pythonGH-101589)
  ...
python-sidebar pushed a commit to python-sidebar/Python-Documentation-Fork-With-TOC that referenced this issue Sep 1, 2024
python-sidebar pushed a commit to python-sidebar/Python-Documentation-Fork-With-TOC that referenced this issue Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants