-
Notifications
You must be signed in to change notification settings - Fork 53
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
Go pointer passing restriction violated in out_multiinstance? #18
Comments
Hey @l2dy, thanks for pointing this out. I have been reading through the cgo docs and I have to admit my understanding of the restrictions of passing memory between C and Go is not 100%. I have asked around in the Gophers slack about these rules and the documentation to better clarify my understanding. From what I understand, what you described here might not be an issue because the call to Additionally, the other problem we have ran into with sharing context in this way is if you use a fully managed Go value as the context Go's GC will reuse this memory after the Init function completes since it think's there is no references remaining. This is easily fixed via running If you are able to reproduce an issue with the example I would love to investigate further. Please let us know if you have problems with it! |
Referencing the original C string in memory pointed to by a C pointer is OK from the Go side, but putting a Go pointer there is not.
|
Simply put,
|
@l2dy Thanks! We were able to reproduce the issue by creating a lot of memory allocations and GC events in a separate goroutine. I think the solution we have not only violates the rule you highlighted but, having read the pointer section again, it probably violates a few other statements there. Do you have any proposed solutions? What I was thinking is perhaps have Set/Get Context helper functions that store the context in package global slice and then just pass index into that slice around. We experimented with that just now and it seems to work. |
@wfernandes and I pushed some changes to avoid passing Go pointers into C but keep the same ABI. fluent-bit-go/examples/out_multiinstance/out.go Lines 21 to 22 in fc386d2
fluent-bit-go/examples/out_multiinstance/out.go Lines 35 to 36 in fc386d2
fluent-bit-go/output/output.go Lines 70 to 81 in fc386d2
Let us know what you think. |
Should I'm not sure if "All operations on these types must happen in C" applies to your implementation. I would use |
If your recent changes survived GC stress testing, I think we can close this issue now. |
Are plugins initialized in parallel?
|
After reading the
|
From what I remember they were initialized serially. We mainly kept the cc/ @wfernandes |
I'd change it to an integer type and let |
Closes fluent#18. Signed-off-by: Zero King <[email protected]>
I have discovered a non-breaking fix for the miuse of unsafe.Pointer, see #28. |
Closes fluent#18. Signed-off-by: Zero King <[email protected]>
In the
out_multiinstance
example, pointer of the Go stringid
is stored in memory pointed to by a C pointer (plugin
argument of FLBPluginInit) inFLBPluginSetContext
, which I think violates the restrictions on passing pointers between Go and C.The text was updated successfully, but these errors were encountered: