1

I'm on Ubuntu 20, working on a Rails 6.05 project with a Postgres DB. I've succesfully created a Heroku app using heroku create appname and then deployed the Rails app using git push heroku master.

The app/website is accessible and works fine on Heroku, but I'm not being able to run most console commands using the Heroku cli.

I can deploy as described above, and also set environment variables via heroku config:set TWILIO_KEY='123', but commands like heroku run rails db:migrate, heroku run rails console and most if not any other commands that I try to run via heroku run command return the following error (IP changes every time):

Running rails console on ⬢ appname... done
Error: connect ECONNREFUSED 54.175.164.234:5000

Right after I run any of these commands from my console, I can see the app logs on Heroku updating accordingly and throwing an error.

For example, for the heroku run rails console command executed above, the app logs show:

2022-05-31T00:42:11.048694+00:00 app[api]: Starting process with command `rails console` by user [email protected]
2022-05-31T00:44:34.314621+00:00 heroku[run.6356]: Awaiting client
2022-05-31T00:44:34.307905+00:00 heroku[run.6356]: State changed from starting to up
2022-05-31T00:45:04.332589+00:00 heroku[run.6356]: Process exited with status 128
2022-05-31T00:45:04.332006+00:00 heroku[run.6356]: Error R13 (Attach error) -> Failed to attach to process
2022-05-31T00:45:04.389840+00:00 heroku[run.6356]: State changed from up to complete

The Heroku docs do not provide more information on R13 or status 128 error codes.

The error code itself does not provide any other information regarding the connection to what is failing either.

Troubleshooting: Since it clearly doesn't seem to be a connection issue with Heroku itself but rather the project, I did a clean Ubuntu install on a laptop, disabled all firewall rules and attempted to run heroku run rails console on both new and old projects that I used to manage just fine. To my surprise (not) I get the same error on all the projects I try to connect to, new or old.

This got me thinking, could it be a Postgres connection problem of some sort? Is there anything that I could have missed in the setup (eg: in config/environments/production.rb or database.yml) when deploying an app with a Postgres DB to production that might be causing the problem?

Any help would be appreciated.

8
  • Just to verify it's not a connection issue - can you telnet Heroku? Commented May 31, 2022 at 22:34
  • Hello. I'm trying to run the command suggested in the official docs you provided and I get telnet: could not resolve rendezvous.runtime.heroku.com/5000: Name or service not known Commented May 31, 2022 at 22:40
  • Also, I can push to Heroku, set env variables, turn maintenance mode on/off. It seems the connection works, but I can't attach to the Heroku console from my console, as the error in the Heroku logs show. Commented May 31, 2022 at 22:46
  • Does telnet 54.175.164.234 5000 work from your box? (IP taken from your output.) Commented May 31, 2022 at 23:10
  • 1
    Thanks. This got me on the right track. I thought it was something with the app configuration, but it was indeed a problem with my ISP. I ran a tracert on the IP listed above and could easily see that it could not find a route to the Heroku servers. I tried using a VPN and it worked. Now I will test if changing the Heroku region fixes the problem, as it should use a different route to reach the Heroku servers. That will hopefully fix the error. Commented Jun 1, 2022 at 12:11

1 Answer 1

0

This problem was related to my ISP blocking connections using port 5000, and it was evident when running a telnet I could not connect directly to the server either.

A workaround that works if you can't get your ISP to fix it is using a VPN.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .