Fixed crash in finalizer of CLR types defined in Python, that survive engine shutdown by lostmsu · Pull Request #1260 · pythonnet/pythonnet
Repository navigation
Fixed crash in finalizer of CLR types defined in Python, that survive engine shutdown - #1260
Merged
filmor merged 1 commit into pythonnet:master from losttech:bugs/1256 Dec 18, 2020
Merged
Fixed crash in finalizer of CLR types defined in Python, that survive engine shutdown #1260 filmor merged 1 commit into pythonnet:master from losttech:bugs/1256
Conversation
lostmsu commented Oct 13, 2020
Copy link Copy Markdown
Member
What does this implement/fix? Explain your changes.
During engine shutdown all links from Python to .NET instances are severed. If an instance of CLR class defined in Python survives the shutdown (for example, a reference is stored in static field) and later gets finalized, it will attempt to severe link again, which is an invalid operation.
The fix is to check if the link has already been severed and skip that step during finalization.
Additionally in this change: refactored MoveClrInstancesOnwershipToPython
Does this close any currently open issues?
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
- Add yourself to
AUTHORS - Updated the
CHANGELOG
9498c07 to
927f980
Compare
October 13, 2020 17:26
lostmsu commented Oct 13, 2020 · edited Loading
Copy link Copy Markdown
Member
Author
|
Interesting. It appears, that the fix is legitimate, but the test for it causes segfault in soft shutdown mode with xplat. Which probably means it is caused by a separate issue :/ |
codecov-io commented Oct 13, 2020 · edited Loading
Copy link Copy Markdown
Codecov Report
@@ Coverage Diff @@ ## master #1260 +/- ## ======================================= Coverage 86.25% 86.25% ======================================= Files 1 1 Lines 291 291 ======================================= Hits 251 251 Misses 40 40
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov .
|
lostmsu commented Nov 11, 2020
Copy link Copy Markdown
Member
Author
|
@amos402 I could see it being freed by one of |
amos402 commented Nov 13, 2020
Copy link Copy Markdown
Member
|
pythonnet/src/runtime/classderived.cs Lines 77 to 80 in 927f980
It set by a weak GCHandle instead after it freed. |
tminka commented Dec 17, 2020
Copy link Copy Markdown
Contributor
|
I have successfully avoided the problem mentioned by @amos402 above via the following commit . |
fixed crash in finalizer of CLR types defined in Python, that survive...
1fd6dc2
... engine shutdown pythonnet#1256 pythonnet#1256 During engine shutdown all links from Python to .NET instances are severed. If an instance of CLR class defined in Python survives the shutdown (for example, a reference is stored in static field) and later gets finalized, it will attempt to severe link again, which is an invalid operation. The fix is to check if the link has already been severed and skip that step during finalization.lostmsu force-pushed the bugs/1256 branch from
927f980 to
1fd6dc2
Compare
December 17, 2020 19:49 filmor merged commit
e2ab3ae
into
pythonnet : master
Dec 18, 2020
BadSingleton
pushed a commit
to Unity-Technologies/pythonnet
that referenced
this pull request
Dec 18, 2020
fixed crash in finalizer of CLR types defined in Python, that survive...
94f29a7
... engine shutdown (pythonnet#1260) pythonnet#1256 pythonnet#1256 During engine shutdown all links from Python to .NET instances are severed. If an instance of CLR class defined in Python survives the shutdown (for example, a reference is stored in static field) and later gets finalized, it will attempt to severe link again, which is an invalid operation. The fix is to check if the link has already been severed and skip that step during finalization.BadSingleton pushed a commit to Unity-Technologies/pythonnet that referenced this pull request Dec 18, 2020
fixed crash in finalizer of CLR types defined in Python, that survive...
3069285
... engine shutdown (pythonnet#1260) pythonnet#1256 pythonnet#1256 During engine shutdown all links from Python to .NET instances are severed. If an instance of CLR class defined in Python survives the shutdown (for example, a reference is stored in static field) and later gets finalized, it will attempt to severe link again, which is an invalid operation. The fix is to check if the link has already been severed and skip that step during finalization.Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment