1

I am working on getting webhook to land in rails application. My rails server runs and I have already connected to ngrok and external application. But that errors to point out my application doesn't run.

localhost:3000 runs and I can get webhooks to ngrok. What's the matter?


The connection to http://9xxxxxx5.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:3000.

Make sure that a web service is running on localhost:3000 and that it is a valid address.

The error encountered was: dial tcp [::1]:3000: getsockopt: connection refused


After I see localhost:3000, rails application runs. Why that could not connect....

Here is the result ps aux | grep ruby.

user               63542   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/assets
user               63541   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/channels
user               63540   0.0  0.0  4298800     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/test/mailers/previews
user               63539   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.04 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/uploaders
user               63538   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/services
user               63537   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/models
user               63536   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/mailers
user               63535   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/jobs
user               63534   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/helpers
user               63533   0.0  0.0  4306992     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/app/controllers
user               63532   0.0  0.0  4298800     40 s000  S+    7:00PM   0:00.05 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/db
user               63531   0.0  0.0  4298800     40 s000  S+    7:00PM   0:00.06 /Users/xxxxxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rb-fsevent-0.10.3/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/xxxxxx/Workspace/app/config/locales
user               64927   0.0  0.0  4258736    192 s002  R+    7:42PM   0:00.00 grep ruby

Update

I have tried to kill last one. But I couldn't because process number is random every time like below:

And I could not connect ngrok still ....

k10a
  • 555
  • 4
  • 14

2 Answers2

1

Thanks @lascostenycoder

I'm so surprised that I could fix that after sudo vi /etc/hosts. I had edited for other projects with MAMP. So I could not do that.

Thanks for your help :)

k10a
  • 555
  • 4
  • 14
  • I actually thought of this yesterday but not sure why I didn't suggest to check that. I updated my answer since I should have mentioned that as well. – lacostenycoder Mar 22 '19 at 13:20
0

You need to add the port to your ngrok command, rails default local development is 3000

ngrok http 3000

Then you should be able to type your ngrok address in your browser

http://xxxxxx.ngrok.io/

The only way I'm able to reproduce your error is to stop my rails server, then when I try to open the ngrok url I get your error. So this means either your server is NOT running or ngrok can't connect to it.

UPDATE 2

Make sure you don't have anything going on in /etc/hosts that could cause a problem.

Update

Make sure you don't have any rogue ruby processes running. Based on your updated comment run this to kill them all

ps aux | grep ruby | awk '{print $2}' |  xargs kill -9

Or try to see if spring is the problem:

spring status
spring stop

Then check and make sure everything has been killed, then start over from step 1.

ps aux | grep ruby

It may be something specific to your app/config? So try to kill all your running rails servers, if you're not sure, restart your machine. Then go to a new project folder, just add a new rails app and once it's running, try ngrok again and see if it works. Also make sure you use http and https in your ngrok command.

lacostenycoder
  • 8,780
  • 3
  • 23
  • 38
  • Thanks for your comment. I run `ngrok http 3000` and then I checked http://xxxx.ngrok.io on display in Terminal. But that would not work. – k10a Mar 22 '19 at 01:41
  • @k10a is your rails server running in another terminal before you run `ngrok` ? And of course the `xxxx` is fake, you'll get a new random hash prefix each time you run a new `ngrok` – lacostenycoder Mar 22 '19 at 01:45
  • Yeah I launched rails server before ngrok and I replace from xxxx to own ngrok url. – k10a Mar 22 '19 at 02:01
  • @k10a how are you launching rails server? – lacostenycoder Mar 22 '19 at 02:06
  • Thanks for your help. In termnial, `$ rails s` as usual. – k10a Mar 22 '19 at 02:45
  • Thanks for your help. I really appreciate that but I could not connect after trying which you told me... – k10a Mar 22 '19 at 04:37