Skip to content
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

Make native module rerequirable. #5016

Closed
waaaagit opened this issue Feb 1, 2016 · 8 comments
Closed

Make native module rerequirable. #5016

waaaagit opened this issue Feb 1, 2016 · 8 comments
Labels
feature request Issues that request new features to be added to Node.js. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. module Issues and PRs related to the module subsystem.

Comments

@waaaagit
Copy link

waaaagit commented Feb 1, 2016

I'm a node embedder, using node v4.2.4

In my situation,
sometimes, I need to unrequire module.(Which I delete module cache in require.cache).
sometimes, I need to refresh the global object to clean the symbol.

In those case,
the .node library probably loaded before. after unrequire module or refresh global object, I got error like 'non self-register'.

The pure JS module and the buildin module are FINE.

Simple test code:

require('iconv');
delete require.cache["C:\\Program Files (x86)\\nodejs\\node_modules\\iconv\\lib\\iconv.js"];
delete require.cache["C:\Program Files (x86)\nodejs\node_modules\iconv\build\Release\\iconv.node"];
require('iconv');
@mscdex mscdex added module Issues and PRs related to the module subsystem. feature request Issues that request new features to be added to Node.js. labels Feb 1, 2016
@rvagg
Copy link
Member

rvagg commented Feb 1, 2016

@waaaagit so you're wanting to be able to unload compiled native addons just like you can do with the require.cache for JavaScript libraries?

I guess this means using uv_dlclose() on a loaded lib, perhaps providing a process.dlclose() as a reverse of process.dlopen(). I'm not sure what the cross-platform consequences of this are and whether it would really unload an addon properly across the various OSs we support. Someone else might have to chime in on that question. @bnoordhuis, @saghul?

@waaaagit
Copy link
Author

waaaagit commented Feb 1, 2016

Actually, I wanting make native module rerequirable, not unload native module.

Because I use node's multi context feature. If a native module loaded in a context, it can't load by other context :(

I think this is not just a feature request, but also a bug for multi context feature.
@rvagg

@rvagg
Copy link
Member

rvagg commented Feb 1, 2016

OK, so this in src/node.cc is probably relevant:

// DLOpen is process.dlopen(module, filename).
// Used to load 'module.node' dynamically shared objects.
//
// FIXME(bnoordhuis) Not multi-context ready. TBD how to resolve the conflict
// when two contexts try to load the same shared object. Maybe have a shadow
// cache that's a plain C list or hash table that's shared across contexts?

@waaaagit
Copy link
Author

waaaagit commented Feb 1, 2016

Well, node has been supporting multi-context feature for a long time. I hope node embedders don't need to wait too long for this bug fix :)

@bnoordhuis
Copy link
Member

There are two pieces to this issue. One is loading and unloading of shared objects in a multi-context environment, the other is making add-ons multi-context aware.

iconv, for example, isn't currently multi-context ready but can be made to with little effort. Many other add-ons however have tons of global state and won't be so easy to adapt.

(Some dynamic linkers support loading a shared object more than once at different addresses. But it's not portable and won't help if the global state is something like a log file.)

Apropos core support, a NODE_MODULE_CONTEXT_AWARE initializer macro for add-ons exists in src/node.h but it hasn't been hooked up to process.dlopen() yet. I don't have time (or, if I'm honest, inclination) to work on that but it shouldn't be hard to implement the machinery for it.

@rustyconover
Copy link
Contributor

+1

@rustyconover
Copy link
Contributor

You can see some of the pain caused by this looking at: request/request-promise#89

@targos targos changed the title Make module rerequirable. Make native module rerequirable. Aug 14, 2016
@Trott Trott added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Jul 9, 2017
jmurzy added a commit to jmurzy/nodegit that referenced this issue Aug 14, 2017
A summary of why this change was required is discussed in the following issues:

jestjs/jest#3552
jestjs/jest#3550
nodejs/node#5016
jmurzy added a commit to jmurzy/nodegit that referenced this issue Aug 14, 2017
Discussion on why this change was required can be found in the following issues:

jestjs/jest#3552
jestjs/jest#3550
nodejs/node#5016
jmurzy added a commit to jmurzy/nodegit that referenced this issue Aug 14, 2017
Discussion on why this change was required can be found in the following issues:

jestjs/jest#3552
jestjs/jest#3550
nodejs/node#5016
sorenlouv pushed a commit to sorenlouv/nodegit that referenced this issue Oct 1, 2017
Discussion on why this change was required can be found in the following issues:

jestjs/jest#3552
jestjs/jest#3550
nodejs/node#5016
@nodejs nodejs deleted a comment from simlu Oct 29, 2017
@refack
Copy link
Contributor

refack commented Nov 11, 2018

Put into https://github.com/nodejs/node/projects/13 backlog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

No branches or pull requests

7 participants