Neon: Context-aware modules support

Created on 9 Dec 2019  路  12Comments  路  Source: neon-bindings/neon

I'd like to build a context-aware node module. I don't think there's a way to achieve that currently.
Relevant refs:

Most helpful comment

I will be happy to contribute on my spare time.

All 12 comments

@MOZGIII This is an awesome point and I'd love to make progress on it! I'm curious if you have tried this out at all鈥擨 thought about it a bit and I think we may have some of the pieces in place already, maybe accidentally. :P But it's certainly not tested and I could believe it doesn't work. We should probably create some test cases to work from.

I think I'm trying to do the same as MOZGIII above: use a neon-compiled crate from electron. Judging from the warnings electron throws at me, it seems that neon-generated modules aren't context aware.

I don't know node or neon well enough to figure out what to change but I'll happily help debug it if you tell me what to tweak where.

Repro: take @amilajack's electron app example at https://github.com/neon-bindings/examples/tree/master/electron-app (loads the package and launches electron) and https://github.com/amilajack/neon-hello (the actual rust/neon code)

Update the electron version to 9.0.3 (though even with version 7 a warning is shown about non-context-aware modules) and it stops working.

Then if you set app.allowRendererProcessReuse = false in the main.js file, it starts working again -- with a nasty warning.

@kjvalencik @dherman
Is there any progress on it?

@rousan While we would be happy to accept a PR to resolve this issue; we have decided to focus most of our efforts on delivering N-API since it will inherently resolve this issue.

I will be happy to contribute on my spare time.

I did a little investigation and while the effort to do this _safely_ is very minimal (it only requires marking the module as context aware), being able to perform this _without leaking memory_ is much higher.

Could you elaborate please?

Nothing inside neon won't work in a context aware module. For example, the global class map is still appropriately scoped.

However, neon does not have any mechanism to clean-up memory on long lived objects. For example, that class map or Js functions that wrap rust functions. It means that each time a worker is created and destroyed, memory would leak.

Any progress on this topic?

@exellian The napi backend is context aware. We have prioritized finishing the napi backend above completing this for the legacy backend.

Ok great

Was this page helpful?
0 / 5 - 0 ratings