Failed to optimize image: unknown reason

Hey everyone :wave:

We’ve just completed a migration of one of our forums from one box to another, while changing the domain at the same time.

In the new installation we’re getting a lot of these errors in our logs

image

lib/discourse.rb:810:in `block in warn'
lib/discourse.rb:804:in `each'
lib/discourse.rb:804:in `warn'
/var/www/discourse/app/models/optimized_image.rb:329:in `rescue in convert_with'
/var/www/discourse/app/models/optimized_image.rb:311:in `convert_with'
/var/www/discourse/app/models/optimized_image.rb:305:in `optimize'
/var/www/discourse/app/models/optimized_image.rb:289:in `resize'
/var/www/discourse/app/models/optimized_image.rb:97:in `block in create_for'
/var/www/discourse/app/models/optimized_image.rb:19:in `block in lock'
/var/www/discourse/lib/distributed_mutex.rb:33:in `block in synchronize'
/var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:14:in `synchronize'
/var/www/discourse/app/models/optimized_image.rb:18:in `lock'
/var/www/discourse/app/models/optimized_image.rb:68:in `create_for'
/var/www/discourse/app/models/upload.rb:167:in `rescue in get_optimized_image'
/var/www/discourse/app/models/upload.rb:161:in `get_optimized_image'
/var/www/discourse/app/models/upload.rb:147:in `create_thumbnail!'
/var/www/discourse/lib/cooked_post_processor.rb:281:in `convert_to_link!'
/var/www/discourse/lib/cooked_post_processor.rb:487:in `block in post_process_images'
nokogiri-1.13.3-x86_64-linux/lib/nokogiri/xml/node_set.rb:233:in `block in each'
nokogiri-1.13.3-x86_64-linux/lib/nokogiri/xml/node_set.rb:232:in `upto'
nokogiri-1.13.3-x86_64-linux/lib/nokogiri/xml/node_set.rb:232:in `each'
/var/www/discourse/lib/cooked_post_processor.rb:486:in `post_process_images'
/var/www/discourse/lib/cooked_post_processor.rb:44:in `block in post_process'
/var/www/discourse/lib/distributed_mutex.rb:33:in `block in synchronize'
/var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:14:in `synchronize'
/var/www/discourse/lib/cooked_post_processor.rb:40:in `post_process'
/var/www/discourse/app/jobs/regular/process_post.rb:26:in `block in execute'
/var/www/discourse/lib/distributed_mutex.rb:33:in `block in synchronize'
/var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:14:in `synchronize'
/var/www/discourse/app/jobs/regular/process_post.rb:10:in `execute'
/var/www/discourse/app/jobs/base.rb:232:in `block (2 levels) in perform'
rails_multisite-4.0.0/lib/rails_multisite/connection_management.rb:80:in `with_connection'
/var/www/discourse/app/jobs/base.rb:221:in `block in perform'
/var/www/discourse/app/jobs/base.rb:217:in `each'
/var/www/discourse/app/jobs/base.rb:217:in `perform'
sidekiq-6.4.1/lib/sidekiq/processor.rb:196:in `execute_job'
sidekiq-6.4.1/lib/sidekiq/processor.rb:164:in `block (2 levels) in process'
sidekiq-6.4.1/lib/sidekiq/middleware/chain.rb:138:in `block in invoke'
/var/www/discourse/lib/sidekiq/pausable.rb:138:in `call'
sidekiq-6.4.1/lib/sidekiq/middleware/chain.rb:140:in `block in invoke'
sidekiq-6.4.1/lib/sidekiq/middleware/chain.rb:143:in `invoke'
sidekiq-6.4.1/lib/sidekiq/processor.rb:163:in `block in process'
sidekiq-6.4.1/lib/sidekiq/processor.rb:136:in `block (6 levels) in dispatch'
sidekiq-6.4.1/lib/sidekiq/job_retry.rb:114:in `local'
sidekiq-6.4.1/lib/sidekiq/processor.rb:135:in `block (5 levels) in dispatch'
sidekiq-6.4.1/lib/sidekiq.rb:40:in `block in <module:Sidekiq>'
sidekiq-6.4.1/lib/sidekiq/processor.rb:131:in `block (4 levels) in dispatch'
sidekiq-6.4.1/lib/sidekiq/processor.rb:257:in `stats'
sidekiq-6.4.1/lib/sidekiq/processor.rb:126:in `block (3 levels) in dispatch'
sidekiq-6.4.1/lib/sidekiq/job_logger.rb:13:in `call'
sidekiq-6.4.1/lib/sidekiq/processor.rb:125:in `block (2 levels) in dispatch'
sidekiq-6.4.1/lib/sidekiq/job_retry.rb:81:in `global'
sidekiq-6.4.1/lib/sidekiq/processor.rb:124:in `block in dispatch'
sidekiq-6.4.1/lib/sidekiq/job_logger.rb:39:in `prepare'
sidekiq-6.4.1/lib/sidekiq/processor.rb:123:in `dispatch'
sidekiq-6.4.1/lib/sidekiq/processor.rb:162:in `process'
sidekiq-6.4.1/lib/sidekiq/processor.rb:78:in `process_one'
sidekiq-6.4.1/lib/sidekiq/processor.rb:68:in `run'
sidekiq-6.4.1/lib/sidekiq/util.rb:56:in `watchdog'
sidekiq-6.4.1/lib/sidekiq/util.rb:65:in `block in safe_thread'

Looking at the code, it appears if the error doesn’t contain convert: then this generic error message is used, so it’s swallowing the actual underlying error.

It feels like this might be a missing prerequisite library on our part, or perhaps some files didn’t make it across during the migration, but it’s hard to tell without the error message. Does anyone have any thoughts on where I should start looking?

My guess here is that ImageMagick is out of date.

Can you confirm you are using our official setup? When we do a ./launcher rebuild we always pull the latest version of the base image.

1 Like

Hey Sam, yep we’re using the ./launcher and have rebuilt several times over the last week.

Is there a way I can quickly monkey patch that script to emit the underlying error? My Ruby is a bit rusty, can I just edit a file or is caching / compilation in play?

Actually, checking our logs this error hasn’t appeared since the other day. Perhaps this was just an issue during our migration :thinking:

My guess here is that the uploads were missing at the time. We tried to optimise images and convert ran and there was no file there.

Our error message can certainly be improved here.

As to debugging, if you need to. I would edit the file inside the container and sprinkle around Discourse.warn calls that (which is basically printf to logs). Restart container after fiddling with the file.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.