postgresql - Rails 3.2 frequent postgres prepared statement already exists errors -
i've been digging around stackoverflow trying find others these prepared statements exists errors.
in cases configuring unicorn after/before fork resolves these issues.
however in case still getting errors such:
activerecord::statementinvalid: pg::error: error: prepared statement "a495" exists: insert "user_logins" ("account_id", "created_at", "ip_address", "user_agent", "user_id") values ($1, $2, $3, $4, $5) returning "id"
this error gets thrown in different areas in our app seems have same statement number 'a495'.
we on rails 3.2.17, using postgres , on heroku.
i have no idea why happening, starting happen more now.
any appreciated.
in rails stack trace error being thrown in .prepare call. i'm confused because checking sql key in statements collection. if doesn't exist prepares new one....however when trying prepare it, throwing error.
def prepare_statement(sql) sql_key = sql_key(sql) unless @statements.key? sql_key nextkey = @statements.next_key @connection.prepare nextkey, sql @statements[sql_key] = nextkey end @statements[sql_key] end
we had same problem, , did thorough investigation. concluded in our case, error caused rack::timeout
, interrupts code execution after new statement has been created, before counter updated on rails side. next prepared statement tries use same name (e.g. a494
), , collision occurred.
my belief rails has not implemented prepared statements correctly. instead of using increasing counter (a001
, a002
, ...), should have used guids. way, race condition described above wouldn't issue.
we didn't find workaround. improving performance of app, , increasing window rack::timeout
, made problem extinct, still happens time time.
Comments
Post a Comment