The blog has moved to http://jessehouse.com/ ... Many google searches point here so I am leaving it operational, but there will be no new posts.

Thursday, November 12, 2009

Heroku - HTTP 502 Error

This might be helpful to someone?

I was receiving 'App Failed To Respond (HTTP 502) Bad Gateway' errors when deploying my application on Heroku. Reading the error codes page did not help me solve the problem, it took awhile but I was finally able to track it down.

The error was being generated in the browser but checking the rails logs, the requests were returning HTTP 200 success codes, so the problem was being generated at the web server level on the Heroku stack.

Turns out the problem was caused by setting response.header for no browser caching. I was using code similar to this post. Everything worked fine after I removed this line

  • response.headers["Expires"] = 0

Heroku - sending email with Gmail

I have been working on deploying a Rails application to Heroku. A couple of gotchas I ran into when following this post "Sending email with Gmail"

  • Don't use a dollar sign ($) in your password 
  • this can work locally if you put single quotes around the value, but on the heroku server it saved the entire string but at runtime would truncate it at the dollar sign
  • for example using the password 'left-side$right-side'
  • heroku config:add GMAIL_SMTP_PASSWORD=left-side$right-side
  • heroku config returns > GMAIL_SMTP_PASSWORD=left-side$right-side
  • heroku console 
  • type ENV['GMAIL_SMTP_PASSWORD'] returns > left-side

Heroku is running Ruby 1.8.6, locally I am running Ruby 1.8.7, I made a small hack to the plugin to avoid errors in development mode

./vendor/plugins/gmail_smtp/init.rb
changed the first line to
require 'smtp_tls' if RUBY_VERSION < "1.8.7" 

tls is already handled in 1.8.7 and this code must have been creating some type of conflict