Error logs contain: duplicate key value violates unique constraint "post_timings_unique"


(Dean Taylor) #1

Error logs contain:

PG::Error: ERROR:  duplicate key value violates unique constraint "post_timings_unique"
DETAIL:  Key (topic_id, post_number, user_id)=(26652, 1, 613) already exists.
: INSERT INTO post_timings (topic_id, user_id, post_number, msecs)
                  SELECT 26652, 613, 1, 1000
                  WHERE NOT EXISTS(SELECT 1 FROM post_timings
                                   WHERE topic_id = 26652
                                    AND user_id = 613
                                    AND post_number = 1)

Backtace:

/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/logster-0.0.10/lib/logster/logger.rb:47:in `add'
/usr/local/lib/ruby/2.0.0/logger.rb:454:in `error'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:360:in `translate_exception_class'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:375:in `rescue in log'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `log'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/var/www/discourse/lib/freedom_patches/active_record_base.rb:7:in `exec_sql'
/var/www/discourse/app/models/post_timing.rb:43:in `record_timing'
/var/www/discourse/app/models/post_timing.rb:69:in `block in process_timings'
/var/www/discourse/app/models/post_timing.rb:67:in `each'
/var/www/discourse/app/models/post_timing.rb:67:in `process_timings'
/var/www/discourse/app/controllers/topics_controller.rb:318:in `timings'

More backtrace:

and this one seams related:
Error:

ActiveRecord::RecordNotUnique (PG::Error: ERROR:  duplicate key value violates unique constraint "post_timings_unique"
DETAIL:  Key (topic_id, post_number, user_id)=(39986, 1, 613) already exists.
: INSERT INTO post_timings (topic_id, user_id, post_number, msecs)
                  SELECT 39986, 613, 1, 202
                  WHERE NOT EXISTS(SELECT 1 FROM post_timings
                                   WHERE topic_id = 39986
                                    AND user_id = 613
                                    AND post_number = 1))

Backtrace

/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rack-mini-profiler-0.9.1/lib/patches/sql_patches.rb:160:in `exec'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rack-mini-profiler-0.9.1/lib/patches/sql_patches.rb:160:in `async_exec'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/var/www/discourse/lib/freedom_patches/active_record_base.rb:7:in `exec_sql'
/var/www/discourse/app/models/post_timing.rb:43:in `record_timing'
/var/www/discourse/app/models/post_timing.rb:69:in `block in process_timings'
/var/www/discourse/app/models/post_timing.rb:67:in `each'
/var/www/discourse/app/models/post_timing.rb:67:in `process_timings'
/var/www/discourse/app/controllers/topics_controller.rb:318:in `timings'

More backtrace


(Sam Saffron) #2

This is a fairly benign race condition. Not urgent to fix cause it self corrects.


(Dean Taylor) #3

Good to know thanks!


(Jeff Atwood) #4