feat(go_port): reproduce race condition with object and class - #888
Open
Schrodinger257 wants to merge 1 commit into
Open
Schrodinger257 wants to merge 1 commit into
Schrodinger257 wants to merge 1 commit into
Conversation
in object and class when calling get or set or call, GO passes o.ptr or c.ptr to the c function. if the c function was doing a work that takes long time to execute before storing the pointer passed to it from GO and GO garbage collector ran while c function still working it will see the object or calss as unreachable as a result it will call their finalizers and free them which causes a segfault when the c function tries to access it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In object (class) when calling get or set or call, GO passes o.ptr (c.ptr) to the c function. if the c function was doing a work that takes long time to execute before storing the pointer passed to it from GO and GO garbage collector ran while c function still working it will see the object (class) as unreachable and as a result it will call their finalizers and free them which causes a segfault when the c function tries to access it.
In this PR i reproduced the race condition as follows:
first creating a py script in memory and load py function that return a class. after it i ran a goroutine that calls garbage collector in the background many times and created an object from the class and called Get("width") on it which triggered the problem and caused a segfault
using defer runtime.KeepAlive() tells the garbage collector that the object (class) must be kept alive during the execution of Get() function and never try to free or call its finalizer. and this solved the problem
Fixes in PR #875