ngrok / ngrok-javascript

Embed ngrok secure ingress into your Node.js apps with a single line of code.
https://ngrok.com
Apache License 2.0
88 stars 18 forks source link

decouple tunnel drop from nodejs gc #2

Closed bobzilladev closed 1 year ago

bobzilladev commented 1 year ago

The customer-facing feature is that the user no longer has to keep around a reference to the javascript object that wraps the underlying tunnel to prevent the tunnel from shutting down. This case can be common, as an http server is listening to a tcp/unix socket and doesn't require a reference to the tunnel wrapper. The above is accomplished by keeping a reference to the underlying tunnel on the rust side to prevent premature dropping.

This PR also adds tunnel.close() and session.closeTunnel() so the user can explicitly shut tunnels down. These calls also remove the rust reference to the underlying tunnel, returning control of dropping the tunnel and session to when NodeJS garbage collects the wrappers.