views:

70

answers:

1

I have a small free app running on heroku.

intermittently the app stops working and displays the default heroku error page on the screen. when I check the logs I see the following:

ActiveRecord::StatementInvalid (PGError: ERROR: current transaction is aborted, commands ignored until end of transaction block : SELECT * FROM "users" WHERE ("users"."password" = E'' AND "users"."userid" = E'') LIMIT 1): app/models/user.rb:5:in authenticate'
app/controllers/admin_controller.rb:6:in
login'

in my controller I am just doing following:

user = User.authenticate(params[:storeid], params[:password])

and in User model:

  def self.authenticate(userid, password)
    user = self.find_by_userid_and_password(userid, password)
    user
  end

The error messages leads me to believe that some connections are left hanging and are never closed. Is this ever a case in a ruby app?

In my app there are also many places where I am using find_by_sql. does that require us to explicitly close connections?

Like this:

@sqlstmmt1 = "INSERT INTO addresses (\"line1\", \"line2\", city, state, zip, county) VALUES ('" + params[:line1] + "', '"+ params[:line2] + "', '"+params[:city]+ "', '" + params[:state] + "', '" + params[:zip]+ "', '" + params[:county]+"')"
sql = ActiveRecord::Base.connection();
sql.begin_db_transaction
A: 

I get that error due to what I think is when trying to insert utf-8 characters, so I guess your password could have exotic characters. BTW: You should escape the sql-string you use, embedding params[:anything] is baaaad.

lelle