-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Go] Run C++ destructors before we panic #2403
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
base: master
Are you sure you want to change the base?
Conversation
Arrange that destructors of local C++ objects in the wrapper function get run before we panic. WIP: Causes some testcases to fail. Fixes swig#1981
The patch here changes the wrapper function structure to look like this:
This means that the cleanup code ( I haven't investigated all the failures, but one awkward one is when the |
Oh but if we copy it then we'd need A fixed sized char array would work but doesn't seem a good approach. |
Will this issue of not deallocating the memory on panics be resolved? We are experiencing our pods being killed due to OOM. |
@henrhoi Sadly I think this has reached the limits of my SWIG/Go knowledge. I used essentially the same approach to successfully fix the same issue for Lua, but differences between Go and Lua mean this doesn't trivially translate over as I'd hoped. Maybe @ianlancetaylor can see a way to resolve this? |
The current implementation of I believe that all the calls of |
@ianlancetaylor I can see several places in SWIG/Go which don't just pass a string literal to One example (which illustrates the general problem) is:
Here If the value passed is expected to often be a string constant we could potentially optimise handling to avoid the copy and temporary buffer in that case using |
Sorry for being unclear. I was only looking at the It seems to me that few functions will call Another approach we could take is to have |
Thanks, @ianlancetaylor, and @ojwb! Contributing to this PR is beyond my SWIG/Go capabilities. Do you think anyone in the maintainer community would be able to solve this? We are experiencing the behavior shown below, where our pods are reaching Gbs of memory before going OOM when experiencing a high load of requests that causes errors, even though the service should only need to use a few Mbs. |
That's probably true for a typical C API, but if you're wrapping a C++ API which throws exceptions you probably need to catch C++ exceptions in every wrapper function (maybe excluding any which are documented never to throw exceptions) - if you're translating them to panic in go then potentially every wrapper function would have a call to
Ian's outlined some solutions to the problem I hit with the lifetime of the panic method. I don't really know any Go but I can try to improve the patch here based on those. Not sure when I'll get to it though. |
Arrange that destructors of local C++ objects in the wrapper function get run before we panic.
WIP: Causes some testcases to fail.
Fixes #1981