Search code examples
rubypostgresqlherokusinatrainternal-server-error

Heroku Internal server error - ruby / Sinatra / Postgresql


I completed a tutorial to learn ruby, Sinatra and Postgresql. My test are passing and the app is working locally on my machine with rackup and localhost:9292. I am trying to export the app on Heroku and I get the following message when I go on the Heroku url: ‘Internal Server error’

It seems to be a common error message with Heroku but I could not relate to any similar topic I found on StackOverflow that were facing this error. I had a feeling that it could be a database issue but following Brian's advice (see below), I've created the database. Please find below the full Heroku logs:


2015-06-30T08:21:54.511756+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:218:in call'
2015-06-30T08:21:54.511757+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:211:incall'
2015-06-30T08:21:54.511758+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/head.rb:13:in call'
2015-06-30T08:21:54.511760+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/methodoverride.rb:22:incall'
2015-06-30T08:21:54.511761+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:181:in call'
2015-06-30T08:21:54.511762+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:2021:incall'
2015-06-30T08:21:54.511763+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in block in call'
2015-06-30T08:21:54.511765+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1795:insynchronize'
2015-06-30T08:21:54.511766+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in call'
2015-06-30T08:21:54.511767+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/handler/webrick.rb:89:inservice'
2015-06-30T08:21:54.511769+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in service'
2015-06-30T08:21:54.511770+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:inrun'
2015-06-30T08:21:54.511771+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in block in start_thread'
2015-06-30T08:21:54.512062+00:00 app[web.1]: 62.252.214.33 - - [30/Jun/2015:08:21:54 +0000] "GET / HTTP/1.1" 500 30 0.0023
2015-06-30T08:48:18.429835+00:00 heroku[api]: Starting process with commandrails consoleby guillaume.bouffard@hotmail.co.uk
2015-06-30T08:48:21.683429+00:00 heroku[run.3694]: Awaiting client
2015-06-30T08:48:21.711122+00:00 heroku[run.3694]: Starting process with commandrails console
2015-06-30T08:48:22.102369+00:00 heroku[run.3694]: State changed from starting to up
2015-06-30T08:48:23.553202+00:00 heroku[run.3694]: State changed from up to complete
2015-06-30T08:48:23.542808+00:00 heroku[run.3694]: Process exited with status 127
2015-06-30T08:54:15.444683+00:00 heroku[router]: at=info method=GET path="/" host=guillaume-bookmark-manager.herokuapp.com request_id=044274e4-694c-47e3-8ee5-1ac35ae8a5c9 fwd="62.252.214.33" dyno=web.1 connect=0ms service=44ms status=500 bytes=326
2015-06-30T08:54:15.446539+00:00 app[web.1]: 2015-06-30 08:54:15 - DataObjects::ConnectionError - could not connect to server: Connection refused
2015-06-30T08:54:15.446547+00:00 app[web.1]:    Is the server running on host "localhost" (127.0.0.1) and accepting
2015-06-30T08:54:15.446549+00:00 app[web.1]:    TCP/IP connections on port 5432?
2015-06-30T08:54:15.446551+00:00 app[web.1]: :
2015-06-30T08:54:15.446553+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/data_objects-0.10.15/lib/data_objects/connection.rb:79:ininitialize'
2015-06-30T08:54:15.446554+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/data_objects-0.10.15/lib/data_objects/connection.rb:79:in new'
2015-06-30T08:54:15.446556+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/data_objects-0.10.15/lib/data_objects/pooling.rb:181:inblock in new'
2015-06-30T08:54:15.446557+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/data_objects-0.10.15/lib/data_objects/pooling.rb:176:in synchronize'
2015-06-30T08:54:15.446559+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/data_objects-0.10.15/lib/data_objects/pooling.rb:176:innew'
2015-06-30T08:54:15.446560+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/data_objects-0.10.15/lib/data_objects/pooling.rb:121:in new'
2015-06-30T08:54:15.446562+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/data_objects-0.10.15/lib/data_objects/connection.rb:68:innew'
2015-06-30T08:54:15.446563+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:251:in open_connection'
2015-06-30T08:54:15.446565+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/dm-transactions-1.2.0/lib/dm-transactions/adapters/dm-do-adapter.rb:69:inopen_connection'
2015-06-30T08:54:15.446593+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in with_connection'
2015-06-30T08:54:15.446594+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:141:inread'
2015-06-30T08:54:15.446597+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/repository.rb:162:in read'
2015-06-30T08:54:15.446598+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/collection.rb:1118:inlazy_load'
2015-06-30T08:54:15.446599+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/support/lazy_array.rb:409:in each'
2015-06-30T08:54:15.446601+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/collection.rb:505:ineach'
2015-06-30T08:54:15.446602+00:00 app[web.1]:    /app/app/views/index.erb:2:in block in singleton class'
2015-06-30T08:54:15.446604+00:00 app[web.1]:    /app/app/views/index.erb:-6:ininstance_eval'
2015-06-30T08:54:15.446605+00:00 app[web.1]:    /app/app/views/index.erb:-6:in singleton class'
2015-06-30T08:54:15.446606+00:00 app[web.1]:    /app/app/views/index.erb:-8:in__tilt_70282199490340'
2015-06-30T08:54:15.446607+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/tilt-2.0.1/lib/tilt/template.rb:155:in call'
2015-06-30T08:54:15.446609+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/tilt-2.0.1/lib/tilt/template.rb:155:inevaluate'
2015-06-30T08:54:15.446610+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/tilt-2.0.1/lib/tilt/template.rb:96:in render'
2015-06-30T08:54:15.446612+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:822:inrender'
2015-06-30T08:54:15.446613+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:666:in erb'
2015-06-30T08:54:15.446615+00:00 app[web.1]:    /app/app/server.rb:25:inblock in '
2015-06-30T08:54:15.446616+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in call'
2015-06-30T08:54:15.446617+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:inblock in compile!'
2015-06-30T08:54:15.446619+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in []'
2015-06-30T08:54:15.446620+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:inblock (3 levels) in route!'
2015-06-30T08:54:15.446621+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:993:in route_eval'
2015-06-30T08:54:15.446623+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:inblock (2 levels) in route!'
2015-06-30T08:54:15.446624+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1014:in block in process_route'
2015-06-30T08:54:15.446625+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:incatch'
2015-06-30T08:54:15.446627+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in process_route'
2015-06-30T08:54:15.446629+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:ineach'
2015-06-30T08:54:15.446628+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:972:in block in route!'
2015-06-30T08:54:15.446630+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:inroute!'
2015-06-30T08:54:15.446631+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1084:in block in dispatch!'
2015-06-30T08:54:15.446633+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:inblock in invoke'
2015-06-30T08:54:15.446634+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in catch'
2015-06-30T08:54:15.446635+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:ininvoke'
2015-06-30T08:54:15.446637+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1081:in dispatch!'
2015-06-30T08:54:15.446744+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:inblock in invoke'
2015-06-30T08:54:15.446746+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in catch'
2015-06-30T08:54:15.446748+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:ininvoke'
2015-06-30T08:54:15.446638+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:in block in call!'
2015-06-30T08:54:15.446749+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:incall!'
2015-06-30T08:54:15.446750+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:894:in call'
2015-06-30T08:54:15.446752+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/methodoverride.rb:22:incall'
2015-06-30T08:54:15.446753+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-flash3-1.0.5/lib/rack/flash.rb:124:in call'
2015-06-30T08:54:15.446755+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:incall'
2015-06-30T08:54:15.446754+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in call'
2015-06-30T08:54:15.446757+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:incall'
2015-06-30T08:54:15.446758+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in call'
2015-06-30T08:54:15.446760+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:incall'
2015-06-30T08:54:15.446769+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in call'
2015-06-30T08:54:15.446770+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:incall'
2015-06-30T08:54:15.446772+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in call'
2015-06-30T08:54:15.446773+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/session/abstract/id.rb:225:incontext'
2015-06-30T08:54:15.446774+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/session/abstract/id.rb:220:in call'
2015-06-30T08:54:15.446776+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/logger.rb:15:incall'
2015-06-30T08:54:15.446777+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/commonlogger.rb:33:in call'
2015-06-30T08:54:15.446779+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:218:incall'
2015-06-30T08:54:15.446780+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:211:in call'
2015-06-30T08:54:15.446781+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/head.rb:13:incall'
2015-06-30T08:54:15.446782+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/methodoverride.rb:22:in call'
2015-06-30T08:54:15.446784+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:181:incall'
2015-06-30T08:54:15.446785+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:2021:in call'
2015-06-30T08:54:15.446786+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:inblock in call'
2015-06-30T08:54:15.446789+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in call'
2015-06-30T08:54:15.446790+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.1/lib/rack/handler/webrick.rb:89:inservice'
2015-06-30T08:54:15.446787+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1795:in synchronize'
2015-06-30T08:54:15.446791+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:inservice'
2015-06-30T08:54:15.446792+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in run'
2015-06-30T08:54:15.446823+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:inblock in start_thread'
2015-06-30T08:54:15.447548+00:00 app[web.1]: 62.252.214.33 - - [30/Jun/2015:08:54:15 +0000] "GET / HTTP/1.1" 500 30 0.0032

And here is the link to the repository.

If any additional information is needed, please let me know; it will also improve my debugging skills to know how to solve by myself Heroku errors in the future.


Solution

  • This is happening because your app seems to be configured to connect to a database hosted on the same server as the app (localhost). Heroku does not work like this.

    You'll need to:

    1. Attach a database: heroku addons:create heroku-postgresql:hobby-dev
    2. Set your app to connect to the Heroku DB

    Here's how you do #2:

    After creating the DB, heroku adds the connection string to your instances environment variables and can be accessed with: ENV['DATABASE_URL']

    DataObjects::Connection.new(ENV['DATABASE_URL'])
    

    If you run into an issue with DATABASE_URL, you can check what URL Heroku assigned to your new database connection string:

    heroku config -s | grep HEROKU_POSTGRESQL
    

    Reference: https://devcenter.heroku.com/articles/heroku-postgresql