I run a Discourse site and I wish to start by saying how much I love this software. Thanks to all the team for the great work, this is an awesome tool.
After a 2.5.0 upgrade, I went into big troubles. Here is the recap and the workaround I did. Maybe this will lead to a much better fix in future versions.
Some of the topics we have in our database contain broken uploads. We used the “S3 uploads” feature and deleted the bucket by mistake. Yes, that’s a very stupid thing to do, but, well, we did! The result was that all the topics images were lost.
Except from the fact we had lost many images, everything was fine, Discourse was showing broken links to non existing pictures, but all was good.
But when we wanted to upgrade to 2.5.0, it went crazy: all logged-in users got 500 errors, while anonymous visitors were able to see the website.
After investigating, I realized Discourse was dying on “No such file” errors. It was trying to download them it seems. I had to force the local? method to true in /var/www/discourse/app/models/upload.rb and that did the trick, but I’m a bit worried about the next upgrades…
This is clearly something new, as previous upgrades did not break.
By the way, is there any method I can follow to remove all the dead image links we have in our topics?
Sure, in my log/production.log, I had the following exception (when Discourse was accessing the empty S3 bucket (which I recreated, hoping it would fix the problem).
Started GET “/” for 86.246.127.170 at 2020-05-16 14:29:06 +0000
Processing by ListController#latest as HTML
Creating scope :open. Overwriting existing method Poll.open.
Completed 500 Internal Server Error in 3638ms (ActiveRecord: 0.0ms | Allocations: 135090)
NoMethodError (undefined method path' for nil:NilClass) /var/www/discourse/lib/file_store/base_store.rb:150:in cache_file’
I can confirm this is not caused by a plugin : I reproduced the same bug with a fresh install + a restore of my last backup and no plugins installed unless docker_manager.
The first stacktrace I get is :
Completed 500 Internal Server Error in 4169ms (ActiveRecord: 0.0ms | Allocations: 72058)
NoMethodError (undefined method path' for nil:NilClass) /var/www/discourse/lib/file_store/base_store.rb:150:in cache_file’
if file.nil?
return
end
FileUtils.cp(file.path, path)
Which lead to a second error (the one I mentioned in my initial post):
Started GET “/” for 86.246.127.170 at 2020-05-18 07:37:40 +0000
Processing by CategoriesController#index as HTML
Completed 500 Internal Server Error in 4342ms (ActiveRecord: 0.0ms | Allocations: 60478)
NoMethodError (undefined method path' for nil:NilClass) /var/www/discourse/app/models/upload.rb:193:in fix_dimensions!’
Which I fixed by forcing local? to true:
def local?
return true
!(url =~ /^(https?:)?///)
end
Yes, I agree, but I’m afraid on running such a nuke by hand on the DB. Any suggestions for doing it “properly”? Or should I do it really “by hand” ?
Also, I have the feeling this change of behavior from Discourse is a bit worrying. It means, as far as I can tell, that if at some point, there’s a dead image link somewhere, the app is going to crash.
It was not the case before. I would suggest to make it more robust in such situations.
Yes this looks like the same issue. @sukria if you update to the latest tests-passed I have added a fix which makes things more robust for broken uploads (although, you should still try to clean up the broken upload references)
Thanks @david, I confirm a fresh rebuild against tests-passed worked out of the box. Thanks!
Any suggestion on a proper/easy way to get rid of those dead links in topics?