Skip to content

Conversation

@yields
Copy link
Contributor

@yields yields commented Apr 10, 2019

Hey,

While investigating a panic in the bindings we found that futures do not use runtime.KeepAlive(), this can cause the future to be destroyed before it is used.

See an example here: https://play.golang.org/p/Lv19twqhDEU

We patched segmentio/foundationdb with this fix, deployed and we no longer see any panics in production.

Worth nothing that we found that other structures that use SetFinalizer() do not use runtime.KeepAlive() as well, but we opted to make minimal changes to the *Future that shows up in the trace.

@alexmiller-apple
Copy link
Contributor

@fdb-build, ok to test

@yields
Copy link
Contributor Author

yields commented Apr 12, 2019

@alexmiller-apple any idea what failed here?

@ajbeamon
Copy link
Contributor

I'm not sure which version of Go we're using to build, but it doesn't recognize runtime.KeepAlive:

bindings/go/build/src/github.com/apple/foundationdb/bindings/go/src/fdb/futures.go:104: undefined: runtime.KeepAlive

@alexmiller-apple
Copy link
Contributor

Oh, I never actually posted.

We're running go 1.3 in our CI, and runtime.KeepAlive was introduced in 1.7.

Tangentially, @AlvinMooreSr is working on getting the image used in the CI updated, so this PR will be stranded for sad reasons for a little while until that happens, but that should hopefully happen sometime soon.

@alexmiller-apple
Copy link
Contributor

I think Alvin mentioned our images got changed and upgraded, so let's try again.

@fdb-build, test this please

@alecgrieser
Copy link
Contributor

Was the go version updated in the build image?

@alecgrieser
Copy link
Contributor

In any case, this change would require also bumping our minimum required go version, which isn't the end of the world, but it would be important to note.

@AlvinMooreSr
Copy link
Contributor

The version of go in the new build image is "go version go1.11.5 linux/amd64". This PR also successfully compiles all go targets via cmake within the new docker image: foundationdb/foundationdb-build:0.1.2 which is already published to docker.com and awaiting integration into our current master branch.

@alecgrieser
Copy link
Contributor

test this please

Copy link
Contributor

@alecgrieser alecgrieser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, well, this seems reasonable enough to me, though I guess I'm somewhat confused of the mechanism. Is the specific thing that the future was somehow being dereferenced in the C specific stuff? I'm not super familiar with the low-level particulars of go like that.

It also looks like the go community doesn't support anything older than 1.11 if I'm reading this page correctly: https://golang.org/doc/devel/release.html#policy So, I'm fine with bumping the required go version, though we need to update our documentation with this change: https://github.com/apple/foundationdb/blob/master/documentation/sphinx/source/downloads.rst#go-11

@ajbeamon
Copy link
Contributor

It seems the basic idea is that from the perspective of Go, there are cases where we were done using a Go level future object while we still had an outstanding native call using the pointer that the future object held. Go would destruct the future object, triggering the finalizer which decremented the reference count of the object at the native level. It must be the case that were deleting the last reference count (either because the operations didn't hold their own reference or due to a race, not sure), and then that left us accessing a deleted object.

The keepAlive tells Go that the object being kept alive can't be deleted prior to the call.

I think we can go ahead and merge this and update the documentation afterward.

@ajbeamon ajbeamon merged commit 2e09a21 into apple:master May 21, 2019
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.

5 participants