8000 `decimal.getcontext` crashes with `--with-decimal-contextvar=no` and `-X showrefcount` · Issue #123657 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

decimal.getcontext crashes with --with-decimal-contextvar=no and -X showrefcount #123657

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

Closed
ZeroIntensity opened this issue Sep 4, 2024 · 2 comments
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@ZeroIntensity
Copy link
Member
ZeroIntensity commented Sep 4, 2024

Crash report

What happened?

cc @godlygeek, who helped me find this

I was investigating a reference leak on the asyncio test suite, and I came across decimal.getcontext leaking some memory. Here's what I was doing:

$ ./python -Xshowrefcount -c "import decimal; decimal.getcontext()"
[207 refs, 0 blocks]

This is a problem in itself, since this is a leak, but after configuring with --with-decimal-contextvar=no, then the above code fails with a negative reference count:

Python/gc.c:92: gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x5d3d7d336490
object refcount : 1
object type     : 0x5d3d7d4acd50
object type name: decimal.Context
object repr     : Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZero, Overflow])

It seems both of these problems were caused by #123244

(@encukou, this needs extension-modules, 3.14 and 3.13)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

Linked PRs

@ZeroIntensity ZeroIntensity added the type-crash A hard crash of the interpreter, possibly with a core dump label Sep 4, 2024
@Eclips4 Eclips4 added extension-modules C modules in the Modules dir 3.13 bugs and security fixes 3.14 bugs and security fixes labels Sep 4, 2024
@Eclips4
Copy link
Member
Eclips4 commented Sep 4, 2024

cc @neonene

@picnixz picnixz changed the title decimal.getcontext is problematic decimal.getcontext crashes with --with-decimal-contextvar=no and -X showrefcount Sep 5, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 6, 2024
…honGH-123703)

(cherry picked from commit 853588e)

Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
encukou pushed a commit that referenced this issue Sep 6, 2024
…-123703) (GH-123774)

(cherry picked from commit 853588e)

Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
@encukou
Copy link
Member
encukou commented Sep 6, 2024

Thanks @ZeroIntensity/@godlygeek for the report, and @neonene for the fix!

@encukou encukou closed this as completed Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

3 participants
0