Repository navigation
segfault when deleting an object after returning it #133371
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorextension-modulesC modules in the Modules dirC modules in the Modules dir
on May 4, 2025 I also have a segfault on this source code snippet.
Moreover, very simplified example like this
def create_obj(): obj = [42] try: return obj finally: del obj o = create_obj() print(o)
also have a problem (assertion, not crash):
python: ./Include/internal/pycore_gc.h:167: _PyGCHead_SET_NEXT: Assertion `(unext & ~_PyGC_PREV_MASK) == 0' failed. [1] 667990 IOT instruction ./python asyncio_segfault.pyIs it in general correct to delete returned object in finally section?
- changed the title
[-]asyncio segfault when deleting an eager asyncio.Task[/-][+]segfault when deleting an object after returning it[/+]on May 4, 2025 Is it in general correct to delete returned object in finally section?
Yes, this is correct
Reacted by Mikhail Efimov1 remaining item
- addedtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
on May 4, 2025 The returned object is being borrowed, so the
delreleases the caller's strong reference, not its own.cc @mpage
The returned object is being borrowed, so the
delreleases the caller's strong reference, not its own.cc @mpage
Yes, this problem appears after this PR was being merged:
#130708I've checked it with
git bisect.Another important detail I've noticed is that
sys.getrefcountresult have changed after this PR.
Maybe this also should be fixed.
Or at least docstring for this method should be adopted.Another important detail I've noticed is that sys.getrefcount result have changed after this PR.
Yeah, there's less strong references being formed, so the reference count isn't as high. Is there anything to document?
I've checked that original code snippet with
asyncio.Taskalso works well (no crash) on the last commit before PR #130708.Yeah, there's less strong references being formed, so the reference count isn't as high. Is there anything to document?
Return the reference count of the object. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to getrefcount().
Text "one higher than you might expect" is not appropriate for this situation.
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)and removedextension-modulesC modules in the Modules dirC modules in the Modules dir
on May 4, 2025 #133383 is merged, can this be closed now?
yes, I believe it was a 3.14 only issue
Reacted by Hugo van Kemenade and Mikhail Efimov- moved this from Todo to Done in Release and Deferred blockers 🚫
on May 5, 2025
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
- StatusShow more project fieldsDone
a slightly minimized segfault:
Originally posted by @graingert in #128306 (comment)
Linked PRs
LOAD_FASTinstructions whose local is killed byDELETE_FAST#133383