DiscourseConnect UniqueViolation on sync_sso

I’m using DiscourseConnect on a forum via Memberful and I’m trying to track down an error which may be a bug or perhaps someone could advise on a workaround.

The username appears to be “first name + incremental number”, however the user already exists so we’re seeing the message below in the error log.

I’m not sure how the sync itself is triggered in order to reproduce but I guess some scheduled task somewhere calls /admin/users/sync_sso.

I installed the latest available update on New Years Eve and did a rebuild of the app, here’s how the error log looks today:

Version: 2.8.13

Message (33 copies reported)

ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_users_on_username"
DETAIL:  Key (username)=(REDACTED) already exists.
)
app/models/discourse_connect.rb:253:in `block in match_email_or_create_user'
lib/distributed_mutex.rb:33:in `block in synchronize'
lib/distributed_mutex.rb:29:in `synchronize'
lib/distributed_mutex.rb:29:in `synchronize'
lib/distributed_mutex.rb:14:in `synchronize'
app/models/discourse_connect.rb:239:in `match_email_or_create_user'
app/models/discourse_connect.rb:121:in `lookup_or_create_user_unsafe'
app/models/discourse_connect.rb:109:in `block in lookup_or_create_user'
lib/distributed_mutex.rb:33:in `block in synchronize'
lib/distributed_mutex.rb:29:in `synchronize'
lib/distributed_mutex.rb:29:in `synchronize'
lib/distributed_mutex.rb:14:in `synchronize'
app/models/discourse_connect.rb:108:in `lookup_or_create_user'
app/controllers/admin/users_controller.rb:471:in `sync_sso'
app/controllers/application_controller.rb:387:in `block in with_resolved_locale'
app/controllers/application_controller.rb:387:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:361:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:198:in `call'

Backtrace

rack-mini-profiler (2.3.3) lib/patches/db/pg.rb:69:in `exec_params'
rack-mini-profiler (2.3.3) lib/patches/db/pg.rb:69:in `exec_params'
activerecord (6.1.6.1) lib/active_record/connection_adapters/postgresql_adapter.rb:672:in `block (2 levels) in exec_no_cache'
activesupport (6.1.6.1) lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
activesupport (6.1.6.1) lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
activesupport (6.1.6.1) lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
activerecord (6.1.6.1) lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `block in exec_no_cache'
activerecord (6.1.6.1) lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log'
activesupport (6.1.6.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
activesupport (6.1.6.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'

Env (abridged)

REQUEST_URI /admin/users/sync_sso
REQUEST_METHOD POST
HTTP_USER_AGENT http.rb/5.1.0
1 Like