summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-09-30 14:22:52 -0700
committerStan Hu <stanhu@gmail.com>2017-09-30 14:25:31 -0700
commitbe9d0c9cbb1576256b86c8476f9182fccf121c91 (patch)
tree1f5949d52529c2e9743c29ca61ae12f0dbdb6030
parent6c33fb846683ca9213dadaa79b0f32f482ebc0bf (diff)
downloadgitlab-ce-sh-thread-safe-markdown.tar.gz
Make Redcarpet Markdown renderer thread-safesh-thread-safe-markdown
The Redcarpet library is not thread-safe as described in https://github.com/vmg/redcarpet/issues/570. Since we instantiate the Redcarpet renderer in a class variable, multiple Sidekiq threads can access the work buffer and corrupt the state. We work around this issue by memoizing the renderer on a thread basis. Closes #36637
-rw-r--r--changelogs/unreleased/sh-thread-safe-markdown.yml5
-rw-r--r--lib/banzai/filter/markdown_filter.rb4
2 files changed, 7 insertions, 2 deletions
diff --git a/changelogs/unreleased/sh-thread-safe-markdown.yml b/changelogs/unreleased/sh-thread-safe-markdown.yml
new file mode 100644
index 00000000000..af7d9d58a9f
--- /dev/null
+++ b/changelogs/unreleased/sh-thread-safe-markdown.yml
@@ -0,0 +1,5 @@
+---
+title: Make Redcarpet Markdown renderer thread-safe
+merge_request:
+author:
+type: fixed
diff --git a/lib/banzai/filter/markdown_filter.rb b/lib/banzai/filter/markdown_filter.rb
index ee73fa91589..5150222f1f1 100644
--- a/lib/banzai/filter/markdown_filter.rb
+++ b/lib/banzai/filter/markdown_filter.rb
@@ -13,7 +13,7 @@ module Banzai
end
def self.renderer
- @renderer ||= begin
+ Thread.current[:markdown_renderer] ||= begin
renderer = Banzai::Renderer::HTML.new
Redcarpet::Markdown.new(renderer, redcarpet_options)
end
@@ -21,7 +21,7 @@ module Banzai
def self.redcarpet_options
# https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
- @redcarpet_options ||= {
+ Thread.current[:redcarpet_options] ||= {
fenced_code_blocks: true,
footnotes: true,
lax_spacing: true,