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
91 stars 18 forks source link

How to stop the Agent #148

Open sammachin opened 1 month ago

sammachin commented 1 month ago

When I close a connection using either the listener.close() or the ngrok.disconnect(listener.url()) methods it does not close down the agent session, I can see the agent still active in my dashboard (with 0 tunnels)

This means that I am unable to start a new agent on another machine as I get the error:

Connect error: failed to connect session: Your account is limited to 1 simultaneous ngrok agent sessions.
You can run multiple simultaneous tunnels from a single agent session by defining the tunnels in your agent configuration file and starting them with the command `ngrok start --all`.
Read more about the agent configuration file: https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config
You can view your current agent sessions in the dashboard:
https://dashboard.ngrok.com/tunnels/agents error_code: ERR_NGROK_108

According to the docs: The close method on a listener will shut it down, and also stop the ngrok session if it is no longer needed. But this does not seem to be working on either 1.0.0, or 1.3.0

nikolay-ngrok commented 1 month ago

Hello @sammachin, have you tried the kill function? Or ngrok.disconnect without any url? I'll investigate further why the session/agent is not closing when using the listener.

sammachin commented 1 month ago

@nikolay-ngrok Hi, thanks for responding, tried both the ngrok.kill() and ngrok.disconnect() but they have the same effect the tunnel is stopped but not the agent.

nikolay-ngrok commented 1 month ago

Another option to try is to control the session explicitly - instead of using the listener factory methods, you could connect a session and later close it when you need? e.g. start with https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-http-minimum.js#L13 and then do https://ngrok.github.io/ngrok-javascript/classes/Session.html#close when you need it?

sammachin commented 1 month ago

@nikolay-ngrok creating the session manually seems to work, but thats a lot of work to do in my code to refactor it for all the options that a user can set, any chance this can be fixed in the ngrok module so that at least kill() stops the agent.

inconshreveable commented 4 weeks ago

just dropping a note here that we're actively working through the design of the next api rev for our SDKs and this is one of the improvements we're going to work on incorporating into the design

grawsom commented 3 weeks ago

I then have an wish, if this is not in the pipe line. It could be nice that when using ngrok website that the part with tunnel/agent stop / restart etc. would work with the agent. Just a small wish. :-)

sammachin commented 3 weeks ago

@inconshreveable Thanks Alan, what sort of timeframe are we looking at to update the SDK? I could refactor my library to control the session directly but thats not a small amount of work and I don't really want to invest my time if its going to be solved upstream as soon as I finish!

inconshreveable commented 3 weeks ago

@sammachin i can't commit to a timeline here but i'd say "no earlier than october"

@grawsom it sounds like you're asking for the SDK to close the session when you use the dashboard 'stop' function, yes?

grawsom commented 3 weeks ago

@inconshreveable I'm just a user and when I install the Ngrok the "normal" way i then have some control in the website.

https://dashboard.ngrok.com/tunnels/agents image

How it would work in your code i don't know, i just know that you could not do this by @sammachin package that uses you code.