{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/2791","labels_url":"https://api.github.com/repos/nodejs/node/issues/2791/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/2791/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/2791/events","html_url":"https://github.com/nodejs/node/issues/2791","id":105775970,"number":2791,"title":"Crash when working with node-ffi on Windows and Mac","user":{"login":"rosen-vladimirov","id":8351653,"avatar_url":"https://avatars.githubusercontent.com/u/8351653?v=3","gravatar_id":"","url":"https://api.github.com/users/rosen-vladimirov","html_url":"https://github.com/rosen-vladimirov","followers_url":"https://api.github.com/users/rosen-vladimirov/followers","following_url":"https://api.github.com/users/rosen-vladimirov/following{/other_user}","gists_url":"https://api.github.com/users/rosen-vladimirov/gists{/gist_id}","starred_url":"https://api.github.com/users/rosen-vladimirov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosen-vladimirov/subscriptions","organizations_url":"https://api.github.com/users/rosen-vladimirov/orgs","repos_url":"https://api.github.com/users/rosen-vladimirov/repos","events_url":"https://api.github.com/users/rosen-vladimirov/events{/privacy}","received_events_url":"https://api.github.com/users/rosen-vladimirov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/buffer","name":"buffer","color":"f7c6c7"},{"url":"https://api.github.com/repos/nodejs/node/labels/confirmed-bug","name":"confirmed-bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-09-10T10:07:30Z","updated_at":"2015-09-11T05:38:56Z","closed_at":null,"body":"Hi,\r\n\r\nOne 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.\r\n\r\nIn 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: \r\n```\r\nAssertion failed: (obj_data) != (nullptr), file src\\node_buffer.cc,  line 150\r\n```\r\nIt looks like the garbage collector had collected something that we are trying to use later.\r\nSo 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.\r\n\r\nYou can find the repro script and the output when DEBUG=* in [this gist](https://gist.github.com/rosen-vladimirov/7f44089c8c35960b7990)\r\nPlease note that the **crash is on global.gc() call**.\r\n\r\nI 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\r\n\r\nWe suspect that [this change](https://github.com/nodejs/node/issues/2484) had not fixed all issues related to buffers and garbage collection.\r\n\r\nThe original issue in **[node-ffi is here](https://github.com/node-ffi/node-ffi/issues/238)**. After some time of debugging, @unbornchikken stated:\r\n> 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. \r\n\r\nCould 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.\r\n\r\nThanks in advance for your help!\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/139458670","html_url":"https://github.com/nodejs/node/issues/2791#issuecomment-139458670","issue_url":"https://api.github.com/repos/nodejs/node/issues/2791","id":139458670,"user":{"login":"indutny","id":238531,"avatar_url":"https://avatars.githubusercontent.com/u/238531?v=3","gravatar_id":"","url":"https://api.github.com/users/indutny","html_url":"https://github.com/indutny","followers_url":"https://api.github.com/users/indutny/followers","following_url":"https://api.github.com/users/indutny/following{/other_user}","gists_url":"https://api.github.com/users/indutny/gists{/gist_id}","starred_url":"https://api.github.com/users/indutny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indutny/subscriptions","organizations_url":"https://api.github.com/users/indutny/orgs","repos_url":"https://api.github.com/users/indutny/repos","events_url":"https://api.github.com/users/indutny/events{/privacy}","received_events_url":"https://api.github.com/users/indutny/received_events","type":"User","site_admin":false},"created_at":"2015-09-11T05:38:56Z","updated_at":"2015-09-11T05:38:56Z","body":"But again, I wouldn't go too far with this. Perhaps 4.0.1 with this fix will be released fast enough."}}