Make Redcarpet::Markdown#render thread safe - #672
Open
tessereth wants to merge 2 commits into
Open
Conversation
ClearlyClaire
added a commit
to ClearlyClaire/mastodon
that referenced
this pull request
May 23, 2019
There are apparently thread-safety issues: vmg/redcarpet#672
ClearlyClaire
added a commit
to glitch-soc/mastodon
that referenced
this pull request
May 23, 2019
There are apparently thread-safety issues: vmg/redcarpet#672
huacnlee
added a commit
to ruby-china/homeland
that referenced
this pull request
Dec 17, 2020
huacnlee
added a commit
to ruby-china/homeland
that referenced
this pull request
Dec 17, 2020
rtucker
pushed a commit
to vulpineclub/mastodon
that referenced
this pull request
Jan 7, 2021
There are apparently thread-safety issues: vmg/redcarpet#672
|
@boazsegev @robin850 we've recently ran into a nasty bug related to this. We were saving a rendered in a constant and that caused weird errors. I'd love to get this merged, so other people won't fall into the same problems. Is there anything missing here or needed to move it forward? |
|
I think there are two main use cases:
My 2¢. |
|
At the least, it should be clearly documented as not thread-safe. I plan to make several objects and attach them to Thread.current. I just needed to know that I needed to do it! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into the same issue as #570 and I've been trying to think of a good way to fix the issue. The solution is not entirely obvious but as far as I can tell, there are a few options:
Redcarpet::Markdownis not thread safe and you should make one per thread.sd_markdown->work_bufsis used to cache memory buffers between renders. This doesn't work in the concurrent world and if we just re-create them for every render there's a noticeable performance hit on subsequent renders using the sameRedcarpet::Markdownobject (~7%). Plus the active encoding is stored in the renderer options making that also not thread safe so we'd have to split those options in two as well.While I could probably implement option 3, I'm not sure it's possible without at least a minor performance hit. So my questions for you are
renderconcurrent? It's fairly likely this will speed up the concurrent case but slow down the sequential case.