I needed to call Rust
code from my Go
code. Then I used C
as my interface. I did this:
I've created a Rust library that takes a CStr
as a parameter, and returns a new processed string back as CStr
.
This code is statically compiled to a static C library my_lib.a
.
Then, this library is statically linked with my Go
code, that then calls the library API using CGo
(Go's representation to C String, just like Rusts's Cstr
).
The final Go binary is sitting inside a docker container in my kubernetes. Now, my problem is that is some cases where the library's API is called, my pod (container) is crashing. Due to the nature of using CStr
and his friends, I must use unsafe
scopes in some places, and I highly suspect a segfault that is caused by one of the ptrs used in my code, but I have no way of communicating the error back to the Go code that could be then printed OR alternatively get some sort of a core dump from Rust/C so I can point out the problematic code. The pod just crashes with no info whatsoever, at least to my knowledge..
So my question is, how can I:
- Recover from panic/crashes that happen inside an
unsafe
code? or maybe wrap it with a recoverable safe scope? - Override the SIG handlers so I can at least "catch" the errors and not crash? So I can debug it.
- Perhaps communicate a signal interruption that was caused in my c-lib that was generated off Rust back to the caller?
I realize that once Rust is compiled to a c-library, it is a matter of C
, but I have no idea how to tackle this one.
Thanks!