-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime/cgo: cgo Process crashing due to fatal error in cgo calls during Go and Python interaction #58290
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
Comments
with the 1.20 release, our current supported versions are 1.19/1.20 |
Could you please let me know the compatible versions in this format? Ubuntu: We are using the current versions: root@ccm-insights-controller-app-5cb78c7ffb-24f2t:/# gcc --version root@ccm-insights-controller-app-5cb78c7ffb-24f2t:/# ldd --version |
I just tried with golang 1.19 and the issue is still getting reproduced. |
From the stack traces those are segfaults with very low addresses ( @writetonikhil, this looks to me like a bug in the C / Python part of your program. I would suggest using |
Ok let me try using runtime.SetCgoTraceback. Will let you know after the testing. |
@bcmills I tried adding your suggested code. But the only things gets added is some "non-go function" lines and other Py operations(like PyArray_Item_INCREF or PyArray_FromScalar or _PyLong_FromNbInt) which I am not able to understand why they are getting called while doing C.PyFinalize() call. There are some hash codes as well. Could you please point me to the documentation of how to read this trace? The trace is like this: 2023-02-06T07:00:00.233Z | 2023/02/06 07:00:00 recommendations_jobs.go:465: tenant=[63db6335995067deeaa84ced - tenant2] failed to import python module 'recommendations' |
RCA: |
The issue is fixed. Thanks for the help. |
The issue started reappearing without a known reason. We haven't made any change to the code but upgraded go version to 1.19.5 because our vulnerability check tool raised vulnerability issues. Any clues would be appreciated.
|
I don't know much about Python but my understanding is that it runs in a single thread. It may be necessary to prevent concurrent calls from Go into Python. Or it may be necessary to ensure that all calls from Go to Python run on the same thread. In general mixing Go and Python in the same program is not well supported, at least not by us. |
Python 3 uses thread-local state. Calls from Python to Go are generally fine (because they stay on the Python thread), but calls from Go to Python need to be careful to lock the goroutine to its thread (or make all of the Python calls within a single C function call) and ensure that the thread-local state has been initialized on it. See https://docs.python.org/3/c-api/init.html#non-python-created-threads. |
Thank for the clue. I am trying this suggestion and well let you know the results. |
Its not working. We are splitting the go and python code into separate microservices interacting with each other using REST APIs. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, tried with 1.18.5
What operating system and processor architecture are you using (
go env
)?Ubuntu 20.04 and 22.04
go env
OutputWhat did you do?
We are using CGO package (https://pkg.go.dev/cmd/cgo) to communicate from our Go code to Python code. This code is deployed in a Docker container where the container restarts as the interaction between Go and Python throws a fatal error. The tracebacks are attached.
CGOTracebacks.txt
These are the code snippets failing:
Case 1: It gives fatal error in C.PyFinalize() call
Case 2: fails in PyErrPrintEx() method
Case 3: Code same as case 2 but fails in PyImportImportModule() module
There is no sequence but randomly fails in any of the above.
What did you expect to see?
We should not get fatal errors.
What did you see instead?
Tracebacks as attached.
The text was updated successfully, but these errors were encountered: