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
node.js addons crash during garbage collection #317
Comments
|
This happens on my Ubuntu 12.04 , but also on my Raspberry Pi. SWIG versions: 3.0.3, 3.0.4. |
|
Still happening with SWIG 3.0.5. |
|
It might be a bug in your code or a bug in what SWIG generates. You need C++ debugging skills to use SWIG, so when you debug your code, you should be able to give some details that others may find time to look at if the fix isn't clear to you once you've debugged it and posted an analysis. |
|
We're using the JS SWIG to interface C++ drivers in nodeJS. If we could auto-generate something like the following, I'd be really excstatic: Note that neither deleting the object with "delete" nor setting it to null run the destructor. The SWIG-generated C++ file shows that much of the plumbing for deleting a class exists. |
|
@wsfulton Is the bug in my code?First of all, my code itself is very simple; this is the interface file (dummy-module.i): I wrapped it with: The node-gyp binding file I use is also quite simple: I built it with: And then I installed it putting the following package.j son file in the build directory: and running This is the javascript code that reproduces the error (gc-issue.js): (Everything is in the repository I linked in my first post) If the bug is in my code, it should be easily spotted. Is the bug in Node?Since I couldn't tell what's wrong with my code, I started looking for problems with Node.JS. I tried running the same js code with a 'safe-dummy-module' written in Javascript (safe-module.js): This is the adapted version of the Javascript code (no-gc-issue.js): Everything works fine, no segmentation fault; so I would say it's not Node's fault, this time. Valgrind debuggingI recompiled the latest Node.JS version (0.10.36) with debugging symbols, I installed libc6-dbg package (Kubuntu 12.04) to get debugging symbols of core C libraries as well, and tried to look at the backtrace. First I built my project as described above ( (The output file is here) There are a lot of memory leaks, most of them involving a call to But what's more interesting is the full backtrace at the end of the run: To me it looks like the pointer to an instance of DummyObject that is about to be garbage-collected, as recorded in SWIG's proxy class, is invalid. Maybe one of all those "Invalid write"s reported by Valgrind has overwritten the value of this pointer? ConclusionsDespite my attemps (all this was done before I wrote my first post), understanding what's the point and fix the problem is beyond my possibilities; I'm afraid it requires some good knowledge of Swig's internal achitecture (at least of the part that supports Javascript). But I thought that Swig developers might be interested in this report: that's why I wrote it. |
|
Thank you very, very much for your post! |
|
With SWIG 4.0.2 and node v12.22.9 |
Creation of a massive number of javascript objects from a swig-built node.js addon results in
segmentation faultwhen node's garbage collector starts. The same does not happen with an equivalent hand-written javascript module.In this repository:
https://github.com/stepugnetti/swig-node-gc-issue
I've a dummy node.js addon to be built with swig by running
makein project's root. The addon just expones a constructor for an empty Object. In the safe folder you can find a Javascript version of it. Now, runningstarts instantiating infinite many copies of the dummy object from the 'safe' module. No problem here (kill with
ctrl-c). However, runningobjects are instantiated with the constructor of the swig-made addon. After few-hundred instantiations the process crashes with glibc complaining about an invalid pointer being freed.
Is this a bug?
The text was updated successfully, but these errors were encountered: