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
86 stars 17 forks source link

Error when closing socket #49

Closed nijikokun closed 1 year ago

nijikokun commented 1 year ago

Using basic hello-world express application, when closing the socket via CTRL+C (twice) I get the following error output:

Click to view application: https://8ff2-107-132-213-237.ngrok.io
^Cngrok closed socket
ngrok closed socket
ngrok closed tunnel: d1fbfc10e879a390f9fe0a716615b608
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: error closing tunnel: Response("No tunnel found with the ID 'd1fbfc10e879a390f9fe0a716615b608'\r\n\r\nERR_NGROK_333\r\n")] {
  code: 'GenericFailure'
}
bobzilladev commented 1 year ago

You should only have to ctrl-c once for an orderly shutdown, so would guess something is blocking, and then the second ctrl-c does a hard kill which doesn't shutdown cleanly. Can you give the example code?

nijikokun commented 1 year ago

Absolutely, here is my example code:

const express = require('express')
const ngrok = require('@ngrok/ngrok')
const app = express()

app.get('/', (req, res) => {
  res.send('Hello World!')
})

ngrok.listen(app).then(() => {
    const url = app.tunnel.url()
    console.log("Click to view application: " + url);
})
nijikokun commented 1 year ago

Adding, I've tried using one CTRL+C and it still occurs, seems like it doesn't matter whether it's one or two.

bobzilladev commented 1 year ago

Shuts down cleanly for me after a single ctrl-c on mac-aarch64 and ubuntu-x86_64, if you've made a request there's a few seconds of delay as things are torn down. What os and architecture are you on?

nijikokun commented 1 year ago

What architecture

MacOS M2, 13.0 (22A380) Running VSCode Running through npm via npm run start

After retrying without npm looks like it's isolated to npm run usage.

bobzilladev commented 1 year ago

Turns out npm double-taps SIGINT to the underlying process, so the handler code is executed twice in very quick succession, will add protections around this.

bobzilladev commented 1 year ago

Updated in https://github.com/ngrok/ngrok-js/pull/51, released in 0.4.1

nijikokun commented 1 year ago

Confirmed working with 0.4.1

➜  ngrok-js-demo npm run start

> ngrok-js-demo@1.0.0 start
> node index.js

Click to view application: https://7226-107-132-213-237.ngrok.io
^C%                                                                                                                                         
➜  ngrok-js-demo 

👍