[next, master] HandleList.Track: Creates an int variable with no references in Go world, only C, causes panics because GC frees it. #218
Labels
No Label
bug
duplicate
enhancement
invalid
question
up for grabs
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: jcarr/git2go#218
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
As mentioned in https://github.com/libgit2/git2go/pull/196#issuecomment-119044811, I've found a reproducible problem where
HandleList.Track
is called to track a Go pointer, but whenHandleList.Get
is later called to retrieve it, there will be a panic (unless Go's GC is turned off viaGOGC=off
environment variable).I think this issue affects both
master
andnext
branches, but this failing test case usesnext
branch.In
HandleList.Track
:Note that the local variable
slot
, of typeint
, created with the value returned byv.findUnusedSlot()
, is only used in the return statement by being taken an address of. That pointer goes into the C world only.When the C world calls back into Go world, it calls
HandleList.Get
to try to retrieve the Go pointer stored by HandleList:The problem is, by now, the Go GC has run and removed the original
slot
local variable, so trying to dereference the handle viaslot := *(*int)(handle)
ends up creating an incorrect value of slot.I've added a bunch of print statements to git2go and here's the stack trace during the fail case. Note when
Track(handle)
is called,slot
value was1
, but when it's reconstructed by dereferencing a pointer inGet(handle)
, despite all pointers being the same, the resultslot
is0
, not1
, causing a panic:Note that the issue disappears if you turn off the GC:
To reproduce it (without the added prints, of course), do:
Then check out its
update-git2go-api
branch. Also installgit2go
on itsnext
branch. And run thego test
command as shown above.I should add, the above issue can be reproduced with
go1.4.2
, but as I just learned, it does not occur withgo1.5beta1
.That doesn't mean it's not an issue in Go 1.5, just that it doesn't happen in the above small test case. It would still potentially happen for larger test cases if the GC happens to trigger. So you need
go1.4.2
to reproduce it with the above steps.#219 has been merged and this issue is resolved on
next
branch.However, as far as I know, this issue affects
master
too and is still unresolved there.@carlosmn, do you want to backport the fix of #219 to
master
branch as well? That would resolve this issue fully.I've done that, see PR #231.