1
votes

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

2
Can you post the full backtrace errors from your rails server in your local terminal?lacostenycoder
Thanks for your comment. But I could not find any errors in rails server because this error may be occured by not connecting ngrok with rails.k10a
what do you mean by click localhost:3000 ?lacostenycoder
type this in the terminal and paste your output in your question. ps aux | grep rubylacostenycoder
@lacostenycoder Thanks so much. I have added the result in questions.k10a

2 Answers

1
votes

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

0
votes

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.