ngrok-javascript icon indicating copy to clipboard operation
ngrok-javascript copied to clipboard

How to stop the Agent

Open sammachin opened this issue 1 year ago • 9 comments

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

sammachin avatar Jul 29 '24 17:07 sammachin

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.

nikolay-ngrok avatar Aug 05 '24 14:08 nikolay-ngrok

@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.

sammachin avatar Aug 05 '24 15:08 sammachin

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?

nikolay-ngrok avatar Aug 05 '24 15:08 nikolay-ngrok

@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.

sammachin avatar Aug 12 '24 11:08 sammachin

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

inconshreveable avatar Aug 16 '24 13:08 inconshreveable

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. :-)

grawsom avatar Aug 19 '24 13:08 grawsom

@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!

sammachin avatar Aug 19 '24 14:08 sammachin

@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?

inconshreveable avatar Aug 19 '24 15:08 inconshreveable

@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.

grawsom avatar Aug 21 '24 12:08 grawsom

@inconshreveable just wondering if there's any news on this? I've not had a chance to make all the changes in my app yet and not sure when I'll have the capacity

sammachin avatar Oct 17 '24 15:10 sammachin

I'm updating the VSCode extension and I've just come across this issue too.

Is there any update on this? Or is handling the session manually the only way to close the agent down for now?

philnash avatar Nov 10 '24 02:11 philnash

hi @philnash, thanks for the comment. Unfortunately, right now, handling the session manually is the right way to do it. I don't have an updated ETA on the timing for the next rev, but it has been delayed and won't happen until next year.

russorat avatar Nov 14 '24 20:11 russorat

I just kill the process Ngrok sdk runs on, to kill the agent. Whenever I restart I have no issues, but this has a lot of code refactor which is not suitable. When fix guys?

victoryosiobe avatar Mar 06 '25 23:03 victoryosiobe

Hi @victoryosiobe!

Thank you for reaching out to us. We apologize for the inconvenience. We are working to get a fix out for this, this week!

ghost avatar Mar 17 '25 18:03 ghost

@dthomasngrokker great to see this is finally fixed, could you confirm which version of the sdk the fix is in so I can update my dependencies

sammachin avatar Mar 18 '25 14:03 sammachin

Hi @sammachin!

Technically, 1.4.1, but I am updating all the versions to be 1.5.0

Please let me know if you have any issues.

ghost avatar Mar 18 '25 15:03 ghost

@dthomasngrokker Hi, Sorry buy I still don't see any updated pacakges with this fix? the last release was 1.4.1 on 8th Aug 2024

sammachin avatar Apr 04 '25 14:04 sammachin