Skip to content

cuda.core: Program.__dealloc__ crashes with AttributeError when construction failed before self._options was set #2876

Description

@Andy-Jost

Summary

Program.__dealloc__ (cuda_core/cuda/core/_program.pyx:103) always calls _cleanup_debug_source(), which unconditionally reads self._options._name (line 111). self._options is only assigned inside _init at line 867. If a Program object is garbage-collected after __cinit__/__new__ but before that assignment runs — for example an exception raised during construction — self._options is still None, and _cleanup_debug_source raises AttributeError: 'NoneType' object has no attribute '_name' from inside __dealloc__. Since __dealloc__ cannot propagate an exception, this surfaces as an unraisable exception via sys.unraisablehook.

Evidence

Seen in CI as a PytestUnraisableExceptionWarning from test_program_compile_cache.py:

Exception ignored in: Program.__dealloc__
AttributeError: 'NoneType' object has no attribute '_name'

First noticed while reviewing warnings surfaced by #2759's new reporting channel; the bug predates that PR.

Suggested fix

Guard the access: if self._nvrtc_name is not None and self._options is not None and self._nvrtc_name != self._options._name:. Worth checking whether other fields __dealloc__/_cleanup_debug_source touch have the same partial-construction gap.

Refs: found during review of #2759.

Activity

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

    bugSomething isn't workingcuda.coreEverything related to the cuda.core module

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions