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

Fix access violation exception on shutdown (#1977) #2380

Closed
wants to merge 1 commit into from

Conversation

Frawak
Copy link

@Frawak Frawak commented May 8, 2024

What does this implement/fix? Explain your changes.

When nulling the GC handles on shutdown the reference count of all objects pointed to by the IntPtr in the reflectedObjects are zero. This caused an exception in some scenarios because Runtime.PyObject_TYPE(reflectedClrObject) is called while the reference counter is at zero, hence, not being guaranteed the Python object is still there and the memory not reclaimed. The solution presented is treating the pointer in reflectedObjects as strong references - incrementing the respective ref count adding to the set and decrementing removing from it or clearing the entire set (the latter is already done after nulling the GC Handles).

Does this close any currently open issues?

#1977
Random Access Violations on shutdown

Any other comments?

...

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Ensure you have signed the .NET Foundation CLA
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

When nulling the GC handles on shutdown the reference count of all objects pointed to by the IntPtr in the `reflectedObjects` are zero.
This caused an exception in some scenarios because `Runtime.PyObject_TYPE(reflectedClrObject)` is called while the reference counter is at zero, hence, not being guaranteed the Python object is still there and the memory not reclaimed.
The solution presented is treating the pointer in `reflectedObjects` as strong references - incrementing the respective ref count adding to the set and decrementing removing from it or clearing the entire set (the latter is already done after nulling the GC Handles).
@lostmsu
Copy link
Member

lostmsu commented May 10, 2024

The tests must be passing for us to review.

@Frawak
Copy link
Author

Frawak commented May 13, 2024

I see what goes wrong. It is a bit more convoluted than I hoped. I'm on it.

@Frawak
Copy link
Author

Frawak commented May 13, 2024

This solution attempt was misled and premature. I have another solution which does not change the principles regarding references. Because the code change and explanation are completely different, I will close this pull request and open a new one. Sorry for the inconvenience.

@Frawak Frawak closed this May 13, 2024
@Frawak Frawak deleted the fix/1977-access-violation branch May 13, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants