Yoctol/bottender

Bottender ngrok "ghost session" prevents tunnel from opening

AwesomeIndustry opened this issue · 1 comments

Describe the bug
Hello,
I'm trying to get the Facebook Messenger channel set up by following the tutorial, but I'm having some trouble getting ngrok to work. I modified dev.js to print out the error object for more details:

catch (err) {
            if (!(err instanceof Error) && err.msg) {
                console.log(err); //<--- New line I added for more debugging
                throw new Error(`ngrok - ${err.msg}`);
            }
            throw err;
        }

And this is the error I got:


> fb-messenger-app@0.1.0 dev
> bottender dev

App has started
server is running on 5000 port...
{
  error_code: 103,
  status_code: 502,
  msg: 'failed to start tunnel',
  details: { err: 'remote gone away' }
}
✖ An unexpected error occurred in provider dev: ngrok - failed to start tunnel
Error: ngrok - failed to start tunnel
    at .../node_modules/bottender/dist/cli/providers/sh/dev.js:67:23
    at Generator.throw (<anonymous>)
    at rejected (.../node_modules/bottender/dist/cli/providers/sh/dev.js:6:65)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
^CApp has quit

(I'm on an M1 Mac running Monterey 12.6)

To Reproduce
Steps to reproduce the behavior:

  1. Build a simple Facebook Messenger Channel following the official guide
  2. Run npm run dev
  3. Get ngrok error

Expected behavior
I expect npm run dev to successfully start ngrok.

Additional context
It seems to me that the error code is either 103 (Account has been suspended) or 502 (limited to a certain number of max addresses), not sure which one it is.

I have ngrok installed via homebrew and when I run it with my access token it says I already have an ngrok session coming from my laptop's IP address. However, running top | grep ngrok or ps aux | grep ngrok reveals that there are no ngrok processes running. I even tried resetting my ngrok auth token and reauthenticating to prevent any old clients from connecting, but it still thinks I have this extra session.

I even edited my ngrok.yml file to delete my authtoken, and the (homebrew) ngrok client connects just fine without an account. However, bottender still gives me the above error. Where is bottender is getting this mystery authtoken and where this "ghost" process coming from? I couldn't find a ngrok.yml file inside my project (only the system-wide ngrok.yml exists). I'm starting to wonder if there's a hardcoded API key in the library somewhere, but I know that's absurd.

Does anyone know where this "ghost session" is coming from?

Update: After some more poking around (and even hardwiring my ngrok token into the ngrok_1.default.connect() call), I'm starting to wonder if ngrok is being started by bottender but bottender can't connect to it to close it, so it stays running. I get some "connection refused" error sometimes before getting the 103/502 error:

> fb-messenger-app@0.1.0 dev
> bottender dev

App has started
server is running on 5000 port...
✖ An unexpected error occurred in provider dev: connect ECONNREFUSED 127.0.0.1:4040
Error: connect ECONNREFUSED 127.0.0.1:4040
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16)
^[[A^CApp has quit