I think have found something likely related to this and that may provide some more clues to the source of the problem. This gets a bit long-winded, so please bear with me.
I noticed today that I have a couple sidekiq jobs that fail and have been retrying for at least a week with the same error as in the /logs.
On the console, if I retry to rebake that specific post, it takes a long time (near 30s) and eventually ends in
error
lib/pretty_text.rb:239:in `eval': terminated (MiniRacer::ScriptTerminatedError)
from lib/pretty_text.rb:239:in `block in markdown'
from lib/pretty_text.rb:691:in `block in protect'
from lib/pretty_text.rb:691:in `synchronize'
from lib/pretty_text.rb:691:in `protect'
from lib/pretty_text.rb:176:in `markdown'
from lib/pretty_text.rb:302:in `cook'
from app/models/post_analyzer.rb:30:in `cook'
from app/models/post.rb:357:in `cook'
from app/models/post.rb:825:in `rebake!'
from (discourse):1:in `<main>'
After some experimenting, it seems it is due to a particular upload reference that is being used multiple times (25+) in the same post:
The time for the post to rebake is proportional to the number of times that image is referenced in it (1-2 seconds per each use). If it is mentioned enough times, it eventually hits the timeout error. However, if another uploaded image is mentioned as many or more times, the rebake is always instant.
Saving the same image and uploading it again doesn’t reproduce the problem. So the issue seems to be with a particular upload reference.
If all this is not odd enough, it gets stranger. Noticing that the re-uploaded image was including the file extension in the upload reference, I tried appending .gif to the problematic upload reference and… then the rebake works instantly as it should – even when the same problematic image is used dozens of times. In other words, I changed something like

to

and, somehow, that made this weird timeout error to go away.
Guess: some reprocessing needs to be done to this image
and for some reason it repeatedly fails, extending the baking process long enough for it to eventually fail? I’m not sure how to go from here.
In any case, this seems like a bug that could use some attention – maybe the @moderators can relocate this to Contribute > Bug if they agree?

