Skip to content

Crash when working with node-ffi on Windows and Mac #2791

Closed
@rosen-vladimirov

Description

Hi,

One of the popular npm modules is node-ffi. We are using it in our code for several different calls, but one of them leads to assertion error in node 3.x or later. As the same code of the node-ffi is working fine with iojs 2.x, node 0.12.x and node 0.10.x and after discussion with node-ffi owners, I came to opening this issue.

In our code we are trying to call methods from CoreFoundation.dll, which is part of iTunes installation. When we have some short calls and our process terminates, everything is working fine. But when our process starts working for some long time, we receive Assertion error:

Assertion failed: (obj_data) != (nullptr), file src\node_buffer.cc,  line 150

It looks like the garbage collector had collected something that we are trying to use later.
So we've tried to simplify the reproduction case and we've found that we fail only when trying to create ForeignFunction for specific method of the dll. Please note - we are not using them in the test script, just using ffi.

You can find the repro script and the output when DEBUG=* in this gist
Please note that the crash is on global.gc() call.

I believe the problem is not in the dll itself, as the same code is working fine with node 0.10, node 0.12, iojs 2.x

We suspect that this change had not fixed all issues related to buffers and garbage collection.

The original issue in node-ffi is here. After some time of debugging, @unbornchikken stated:

The Windows one is interesting. I've tested our latest ffi with many-many DLL-s referenced, including OpenCL from various vendors, and everything works properly. However if I reference that iTunes DLL then I get a crash. I think iTunes is doing some library initialization logic that somehow corrupts io.js 3+'s memory. I can see in the debugger that the error is about GC thinks that memory is occupied but instead it gets nullified somehow.

Could you please advise what's going wrong here? I know that it is related to specific npm module, not to the node itself, but the same module is working fine in all other cases and node versions, only the call to this specific method is failing on iojs 3.x and node 4.0.0.

Thanks in advance for your help!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.confirmed-bugIssues with confirmed bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions