Skip to content

Commit

Permalink
Fix #19524: Protect use of HeaderIdGenerator with synchronized.
Browse files Browse the repository at this point in the history
Hopefully this is the only source of the race condition that we
have been observing.

[Cherry-picked dc6b3cd]
  • Loading branch information
sjrd authored and WojciechMazur committed Jul 2, 2024
1 parent e7653ee commit b48eee3
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ object SectionRenderingExtension extends HtmlRenderer.HtmlRendererExtension:
val idSuffix = repeatedIds.getOrElseUpdate((c, headerText), 0)
val ifSuffixStr = if(idSuffix == 0) then "" else idSuffix.toString
repeatedIds.update((c, headerText), idSuffix + 1)
val id = idGenerator.getId(headerText + ifSuffixStr)

/* #19524 flexmark's `HeaderIdGenerator` does not appear to be thread-safe,
* so we protect its usage with a full `synchronize`.
*/
val id = idGenerator.synchronized {
idGenerator.getId(headerText + ifSuffixStr)
}

val anchor = AnchorLink(s"#$id")
val headerClass: String = header.getLevel match
case 1 => "h500"
Expand Down

0 comments on commit b48eee3

Please sign in to comment.