500 Internal Server Error when approving queued post

Seeing 500 Internal Server Error on 2.9.0.beta4

Error log reads:

RuntimeError (A gateway connection is necessary to call this method! You'll have to do it inside any event (e.g. `ready`) or after `bot.run :async`.)
lib/post_creator.rb:611:in `update_user_counts'
lib/post_creator.rb:215:in `block in create'
lib/post_creator.rb:409:in `block (2 levels) in transaction'
lib/post_creator.rb:408:in `block in transaction'
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'
lib/post_creator.rb:407:in `transaction'
lib/post_creator.rb:205:in `create'
app/models/reviewable_queued_post.rb:77:in `perform_approve_post'
app/models/reviewable.rb:357:in `public_send'
app/models/reviewable.rb:357:in `block in perform'
app/models/reviewable.rb:355:in `perform'
app/controllers/reviewables_controller.rb:200:in `perform'
app/controllers/application_controller.rb:404:in `block in with_resolved_locale'
app/controllers/application_controller.rb:404: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:368: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:202:in `call'

Backtrace

discordrb (3.3.0) lib/discordrb/bot.rb:673:in `gateway_check'
discordrb (3.3.0) lib/discordrb/bot.rb:156:in `servers'
plugins/discourse-discord-sync/lib/utils.rb:72:in `sync_user'
plugins/discourse-discord-sync/plugin.rb:42:in `block (3 levels) in activate!'
activesupport (6.1.4.7) lib/active_support/callbacks.rb:427:in `instance_exec'
activesupport (6.1.4.7) lib/active_support/callbacks.rb:427:in `block in make_lambda'
activesupport (6.1.4.7) lib/active_support/callbacks.rb:235:in `block in halting_and_conditional'
activesupport (6.1.4.7) lib/active_support/callbacks.rb:516:in `block in invoke_after'
activesupport (6.1.4.7) lib/active_support/callbacks.rb:516:in `each'
activesupport (6.1.4.7) lib/active_support/callbacks.rb:516:in `invoke_after'

Env

HTTP HOSTS: removed by me

So it breaks because there is a Discord server that you are syncing with which cannot be reached, and the plugin does not handle that gracefully.

Looking at the plugin code, I see that it also does not do this as an async job, i.e. the save does not complete before Discourse has reached the Discord servers. If this is implemented as an async job then it could also retry automatically in case the Discord server fails. @barreeeiroo

2 Likes